# Struggling to convert response into JSON Object

**URL:** <https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162>\
**Category:** API Testing\
**Tags:** api-testing, katalon-studio\
**Created:** [June 29, 2021, 5:17am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162 "2021-06-29T05:17:11Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [June 29, 2021, 5:17am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/1 "2021-06-29T05:17:11Z")

</div>

Hi there!

I’m having trouble with the snippet “Response Body: Convert to JSON Object.”

I need to convert the following response to a JSON object so I can then verify that the response contains what I expect it to contain.

Here is the response:

{“action”:“find\_work\_order”,“object”:“find\_work\_order”,“returnCode”:0,“msgCode”:“AppMsg”,“msgType”:0,“data”:{“enc”:"[{“result”:[{“facility”:“TIG”,“planner”:“CSHEPHER”,“wodescription”:“CSS TESTING SR96003798”,“wopriority”:“02”,“workordernbr”:“00001201”,“workordertype”:“CO”,“wostatus”:“ACTIVE”}]}]"}}

What do I need to add to the Verification to firstly, convert the response, and secondly verify that the facility is TIG.

P.S. when I have tried to verify that facility is set to TIG, it fails as it believes facility is set to ‘null’

Thank you!

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 29, 2021, 7:58am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/2 "2021-06-29T07:58:54Z")

</div>

Show us what you have done, your code.

If have no idea, please make search in this forum with keyword “ResponseObject JsonSlurper”

By the way, there are a few “JSON Pretty Print” service on the Internet. With it you can check the syntactical validity of any JSON text. For example

- [https://jsonprintpretty.com/](https://jsonprintpretty.com/)

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [June 30, 2021, 11:06pm UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/3 "2021-06-30T23:06:55Z")

</div>

I have provided the response body, I just need to know what to put in the verification script to convert the response into JSON object so then I can verify it.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [June 30, 2021, 11:52pm UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/4 "2021-06-30T23:52:17Z")

</div>

> **[Parse JSON responses with Katalon Studio](https://medium.com/katalon-studio/parse-json-responses-with-katalon-studio-e9e5a63068c3)**
>
> Many people in the Katalon forum have asked about retrieving information from JSON responses and parsing the JSON format in Katalon Studio…

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [July 1, 2021, 10:16pm UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/5 "2021-07-01T22:16:10Z")

</div>

HI, I’ve looked at that but was still unable to convert.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 2, 2021, 12:57am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/6 "2021-07-02T00:57:27Z")

</div>

Your JSON that you shared to us looks odd.

> [@josh.thompson](#):
>
> ` {"enc":"[{"result" `

The above code should possibly be:

` {"enc":[{"result" `

Your test successfully detected a problem in the response. Congrat!

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [July 2, 2021, 2:44am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/7 "2021-07-02T02:44:11Z")

</div>

Thanks for the response but the JSON object is how it should be and what I expect. The problem is that the response body is a string and I need to convert it into a JSON object.

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [July 2, 2021, 2:51am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/8 "2021-07-02T02:51:00Z")

</div>

Okay so this is my response

{  
“enc”:"[{“config”:{“listobj”:[{“text1”:“UPPER”,“text2”:“lower”,“text3”:“REPLACE1234”},{“text1”:“UPPER1”,“text2”:“lower1”,“text3”:“REPLACEXX1234”}],“text1”:“UPPER”,“text2”:“REPLACE1234”,“text3”:“lower”,“text4”:“1234567890”,“text5”:“1234”}}]"  
}

Katalon believes enc’s value is ‘null’. I need a way to fix this.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 2, 2021, 2:52am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/9 "2021-07-02T02:52:38Z")

</div>

Your response is wrong. It is not a valid JSON. I already told you what’s wrong.

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [July 5, 2021, 10:40pm UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/10 "2021-07-05T22:40:58Z")

</div>

Okay here is what is in my verification tab.

import static org.assertj.core.api.Assertions.\*

import com.kms.katalon.core.testobject.RequestObject

import com.kms.katalon.core.testobject.ResponseObject

import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS

import com.kms.katalon.core.webservice.verification.WSResponseManager

import groovy.json.JsonSlurper

import internal.GlobalVariable as GlobalVariable

RequestObject request = WSResponseManager.getInstance().getCurrentRequest()

ResponseObject response = WSResponseManager.getInstance().getCurrentResponse()

Here is the response:  
{  
“enc”:"[{“config”:{“listobj”:[{“listobj1”:[{“text1”:“UPPERTHIS”,“text3”:“lowerthis”},{“text1”:“UPPERTHIS12”,“text3”:“lowerthis12”}],“text1”:“UPPER1”,“text2”:“lower1”,“text3”:“REPLACEXX1234”}],“text1”:“UPPER”,“text2”:“REPLACE1234”,“text3”:“lower”,“text4”:“1234567890”,“text5”:“1234”}}]"  
}

How do I verify that text1 is set to UPPERTHIS (the response must be converted to a JSON object first)

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [July 6, 2021, 12:01am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/11 "2021-07-06T00:01:12Z")

</div>

I have to unescape the JSON, is there a function for this?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 6, 2021, 1:39am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/12 "2021-07-06T01:39:40Z")

</div>

I am saying, the response you got is not a valid JSON.

This is not a valid JSON.

```auto
{"enc": "[{"config":"foo"}]"}

```

The following is a valid JSON.

```auto
{"enc": "[{\"config\":\"foo\"}]"}

```

Do you agree with it?

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [July 6, 2021, 1:41am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/13 "2021-07-06T01:41:37Z")

</div>

It just needs to be unescaped. Are you familiar with that term? If so, can you please tell me how I do that in Katalon?

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 6, 2021, 1:42am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/14 "2021-07-06T01:42:48Z")

</div>

> [@josh.thompson](#):
>
> that in Katalon?

No, you can do nothing in Katalon. Your web server application has a bug. You should fix it first.

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [July 6, 2021, 1:45am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/15 "2021-07-06T01:45:40Z")

</div>

The Web Server most definitely does not have a bug. You are wrong.

The JSON it is sending just needs to be unescaped. Here is some information on what that is so you are aware in the future. [https://onlinejsontools.com/unescape-json](https://onlinejsontools.com/unescape-json)

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 6, 2021, 1:46am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/16 "2021-07-06T01:46:32Z")

</div>

OK. I will quit.

---

<div class="post-metadata">

**Author:** ![josh.thompson](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/josh.thompson/32/16103_2.png) [@josh.thompson](https://forum.katalon.com/u/josh.thompson)\
**Post date:** [July 6, 2021, 11:36pm UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/17 "2021-07-06T23:36:18Z")

</div>

I was able to find a solution. The JSON had to be parsed not just once, but twice using JSON slurper. Then I had to define the correct response as what I expected and used the assert function to make sure the second slurped response was equal to the correct response.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 7, 2021, 12:12am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/18 "2021-07-07T00:12:00Z")

</div>

I looked at your original post and looked at the “source code” of your post. I found the following code fragment.

```auto
{"action":"find_work_order","object":"find_work_order","returnCode":0,"msgCode":"AppMsg","msgType":0,
"data":{"enc":"[{\"result\":[{\"facility\":\"TIG\",\"planner\":\"CSHEPHER\",\"wodescription\":\"CSS TESTING SR96003798\",\"wopriority\":\"02\",\"workordernbr\":\"00001201\",\"workordertype\":\"CO\",\"wostatus\":\"ACTIVE\"}]}]"}}

```

Well, regrettably enough, I found there are many escape sequences of `\"` in it.

You did not use [Markdown code formatting syntax](http://forum.katalon.com/t/use-code-formatting-feature-in-your-posts/23550/4), so I could not see `\"`.

---

<div class="post-metadata">

**Author:** ![kazurayam](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/kazurayam/32/333_2.png) [@kazurayam](https://forum.katalon.com/u/kazurayam)\
**Post date:** [July 7, 2021, 12:14am UTC](https://forum.katalon.com/t/struggling-to-convert-response-into-json-object/56162/19 "2021-07-07T00:14:29Z")

</div>

I want to say to everyone in this forum, when you are to write a post here, please enclose the code fragments in a pair of triple backticks.

 ![code formatting](https://europe1.discourse-cdn.com/katalon/original/3X/3/f/3f0611012346e0c9ee9918c00cfc288c38b29653.png)

Otherwise, backslash character `\` will not be rendered appropriately when others see your post. Your problem might be misunderstood due to missing `\` characters.
