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

Sri56
Tera Contributor

Yes I did:)

Lol, no you haven't! You've marked my answer as helpful which is great but you can mark it correct as well.

Sri56
Tera Contributor

Hi David,

 

If i want to print only one attribute in array, how can i do that?

find_real_file.png

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

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...

Sri56
Tera Contributor

Oh, Thanks.

will check and get back to you.

 

Thanks,

Sri