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 02:53 AM
Yes I did:)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-26-2019 04:38 AM
Lol, no you haven't! You've marked my answer as helpful which is great but you can mark it correct as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-27-2019 11:52 PM
Hi David,
If i want to print only one attribute in array, how can i do that?
Like here in my example, i need to print only resolution.
Code that i'm using is :
var response = r.execute();
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.parse(responseBody);
//current.u_response_body = JSON.stringify(json, null, 2);
if(json){
var arr = json.result;
var len = arr.length;
var rows = "";
var n = 0
if(len > 0){
for(var i=0;i<len;i++){
var score = arr[i].score;
if(score>0){
rows += "* " + arr[i].resolution + "<BR>";
n++;
}
if(n>10){
break;
}
}
}
}
current.u_response_body = rows;
But the response is null.
Please help me.
Thanks,
Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2019 12:40 AM
I can't see an issue with your code but are there any items in the JSON with a score higher than 0.0? If not it's not going to satisfy your if(score > 0) condition...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2019 01:13 AM
Oh, Thanks.
will check and get back to you.
Thanks,
Sri