Parsing String as json

I am testing an api that returns json in the form of a string, for example {“stringJson”:"{“stuff”:[“thing”,“other thing”]}"}

Is there a good way to parse this so I can save “other thing”?

My current method is to use jsonPath to save stringJson and then use scala.util.parsing.json.JSON to parse the rest, but that feels rather suboptimal even if it works.

Use jsonPath(expression).ofType[T] : http://gatling.io/docs/2.1.7/http/http_check.html#http-response-body

Since I have a string that needs to be converted to json nested inside the json object could you exemplify with this object how to access “other thing”?

{
“stringJson”: “{“stuff”:[“thing”,“other thing”]}”
}

If it was only a json it would be easy then I could write

jsonPath("$.stuff[1]")

but I havent managed to get that to work since the value connected to stringJson is a string rather than a json object.

Sorry, I missed that you have escaped JSON inside JSON…

Skip the saving in Session then parse phase: use jsonPath to grab the JSON unescaped String, then parse directly in the check inside a transform.
Don’t use scala.util.parsing.json, that’s a toy and a perf killer. Use a proper JSON parser. Gatling ships with Boon and Jackson.

Thats significantly nicer.

Thanks

I seem to have this exact same issue where I need to path through escaped JSON inside JSON.

Skip the saving in Session then parse phase: use jsonPath to grab the JSON unescaped String, then parse directly in the check inside a transform.

I’m new to Gatling, so what would this solution look like?

(sorry for the zombie thread)