# Parsing String as json

**URL:** <https://community.gatling.io/t/parsing-string-as-json/2851>\
**Category:** Gatling (Open-Source)\
**Created:** [February 29, 2016, 12:45pm UTC](https://community.gatling.io/t/parsing-string-as-json/2851 "2016-02-29T12:45:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrik\_Sjostrom](https://avatars.discourse-cdn.com/v4/letter/h/bc8723/32.png) [@Henrik\_Sjostrom](https://community.gatling.io/u/Henrik_Sjostrom)\
**Post date:** [February 29, 2016, 12:45pm UTC](https://community.gatling.io/t/parsing-string-as-json/2851/1 "2016-02-29T12:45:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 29, 2016, 1:49pm UTC](https://community.gatling.io/t/parsing-string-as-json/2851/2 "2016-02-29T13:49:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Henrik\_Sjostrom](https://avatars.discourse-cdn.com/v4/letter/h/bc8723/32.png) [@Henrik\_Sjostrom](https://community.gatling.io/u/Henrik_Sjostrom)\
**Post date:** [February 29, 2016, 3:22pm UTC](https://community.gatling.io/t/parsing-string-as-json/2851/3 "2016-02-29T15:22:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [February 29, 2016, 3:32pm UTC](https://community.gatling.io/t/parsing-string-as-json/2851/4 "2016-02-29T15:32:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Henrik\_Sjostrom](https://avatars.discourse-cdn.com/v4/letter/h/bc8723/32.png) [@Henrik\_Sjostrom](https://community.gatling.io/u/Henrik_Sjostrom)\
**Post date:** [February 29, 2016, 4:13pm UTC](https://community.gatling.io/t/parsing-string-as-json/2851/5 "2016-02-29T16:13:17Z")

</div>

Thats significantly nicer.

Thanks

---

<div class="post-metadata">

**Author:** ![Andy\_Frey](https://avatars.discourse-cdn.com/v4/letter/a/e79b87/32.png) [@Andy\_Frey](https://community.gatling.io/u/Andy_Frey)\
**Post date:** [June 22, 2017, 4:32pm UTC](https://community.gatling.io/t/parsing-string-as-json/2851/6 "2017-06-22T16:32:00Z")

</div>

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)
