How to convert String field into a JSON format

Sri56
Tera Contributor

Hi All,

I have a string field called 'Response Body' on my incident table.

where i am printing response from one of the API.

Now the response is in string.

Can someone, please help me how to convert this string into a json format.

Please find the attached screenshot for reference.

 

Thanks,

Sri

14 REPLIES 14

Dubz
Mega Sage

Try the below

var json = JSON.parse(current.u_response_body); //or whatever the field is called

Sri56
Tera Contributor

Hi David,

Thanks for the response.

I am using following script:

var responseBody = response.getBody();
var requestBody = r.getRequestBody();
gs.log('Request Body for QVC Integration request: '+requestBody);
gs.log('Response Body for QVC Integration request: '+responseBody);
current.u_response_body = responseBody;
var json = JSON.parse(responseBody);
current.u_response_body = json;

 

But the output as per attachment.

Please help!

 

Thanks,

Sri

OK, so if you're trying to populate a string field with the response body use below:

var responseBody = response.getBody();
var requestBody = r.getRequestBody();
gs.log('Request Body for QVC Integration request: '+requestBody);
gs.log('Response Body for QVC Integration request: '+responseBody);
var json = JSON.stringify(responseBody);
current.u_response_body = json;

Sri56
Tera Contributor

Hi David,

Please find the attached response body.

I think this is appending with '\'.

Though it is not formatted.

 

Please suggest.

 

Thanks,

Sri