JSON feeder to provide entire json object as string

I have an following json array.
[
{
“timestamp”: “<>”,
“restconf_path”: “/devices/device=<>/interfaces/interface=Port-Channel31/state/admin-status”,
“schema_path”: “/interfaces/interface/state/admin-status”,
“target”: “<>”,
“val”: {
“string_val”: “UP”
}
},
{
“timestamp”: “<>”,
“restconf_path”: “/devices/device=<>/network-instances/network-instance=default/protocols/protocol=BFD,BFD/bfd/micro-bfd-sessions/micro-bfd-session=Port-Channel31/state/session-state”,
“schema_path”: “/network-instances/network-instance/protocols/protocol/bfd/micro-bfd-sessions/micro-bfd-session/state/session-state”,
“target”: “<>”,
“val”: {
“string_val”: “UP”
}
}
]

I am reading this JSON using json feeder as follows.
FeederBuilder feederJson = jsonFile(“messages.json”) .circular();

how can i get json object as single String in Java, instead of MAP.

Kindly provide suggestion.

Not sure that’s the right way.
You should maybe use a simple CSV feeder where each entry is JSON encoded in Base64 (use transform to decode)

The whole purpose of the feeder is to create this map…

So, if your value is the whole object, you’ll have to make the indirection.

[
  {
    "jsonValue" : {
      // your actual first value
    }
  }, {
    "jsonValue" : {
      // your actual second value
    }
  }
]

Here, the jsonValue will be the name of the session variable.

Cheers!

Thanks @sbrevet . I modified the json and tried to fetch ’ session.getMap(“jsonvalue”).toString()’ . But still the nested json is received as MAP (val=Map(string_val → UP)).
How can I receive nested json also as JSON

// properly formats into a JSON value (wrap Strings with double quotes, deal with null)
"#{foo.jsonStringify()}"

I am accessing the value inside a function, so I am using Session. I guess inside session we cannot use EL. What is correct way to access the json.

 .exec(session -> {
  String message = replaceFqdn(session.getString("fqdn"), session.getMap("jsonValue").toString());
  Session newSession = session.set("message", message);
  return newSession;
})

I am new to gatling, so Kindly ignore if I did any basic mistakes

JSON feeder to provide entire json object as string

The jsonFile feeder is meant to produce JSON objects.
If coding some workaround to turn JSON objects back into Strings is out of your reach, I really think you should reconsider using jsonFile.

As I explained above, you should encode each JSON object in Base64 so they fit into a CSV line, use a csv feeder and use transform on this feeder to decode the Base64 string into JSON ones.

thanks. I will try with csv.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.