- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2020 01:12 AM
When I send a REST message to another system, I do get a response back, which I'd like to work with (e.g. read out the INC number).
However, I seem to be not able to do so for some reason.
I assume it is a structure of the JSON vs. my Script issue and maybe just need a quick finger point.
{"result":{"parent":"","made_sla":"true","caused_by":""<more>}}
What I'm trying to do is, parsing the JSON object using:
var parsedResponse = JSON.parse(responseBody);
but putting it out in the log just shows me another "object"
Parsed Response: [object Object] Now I tried just parsing that object but can't seem to get anywhere. Is there a clever (and more simple) way to do this?
I mean it's a simple response from another ServiceNow instance.
Solved! Go to Solution.
- Labels:
-
Integrations
-
Multiple Versions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2020 01:28 AM
Hi ChristianRatzlaff,
try the code as shown below, it will print the JSON objects.
var parser = new JSONParser();
var parsedData = parser.parse(responseBody);
var result = parsedData.result.made_sla;
gs.print(result);
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2020 01:24 AM
Hi,
Actually you can fetch the objects of JSON using this way:
v
var data = '{"result":{"parent":"","made_sla":"true","caused_by":""<more>}}'; // Demo json Data
var jsData= JSON.parse(data); // convert json object into javascript object
var madeSla = jsData["result"].made_sla;
var causedBy = jsData["result"].caused_by;
gs.log(madeSla +"result"+ causedBy);
But,you can't print the complete JSON this way
Regards,
Munender
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2020 01:28 AM
Hi ChristianRatzlaff,
try the code as shown below, it will print the JSON objects.
var parser = new JSONParser();
var parsedData = parser.parse(responseBody);
var result = parsedData.result.made_sla;
gs.print(result);
Thank you.