How to convert String field into a JSON format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2019 12:40 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2019 12:48 AM
Try the below
var json = JSON.parse(current.u_response_body); //or whatever the field is called
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2019 01:42 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2019 01:54 AM
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2019 02:15 AM