- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 03:33 AM
I have converted the XML into JSON. But I am unable to get any values from that Json. Also I am not able to get the length. Please help. I want to know how many info there and I want to get the key and value from each info node. I consider each info is single record.
{
"soap:Envelope": {
"xmlns:soap": "http://www.w3.org/2003/05/soap-envelope",
"soap:Body": {
"customerListResponse": {
"xmlns": "http://ei2.nobj.nable.com/",
"return": [
{
"info": [
{
"value": "622",
"key": "customer.customerid"
},
{
"value": "All Covered - Workspaces",
"key": "customer.customername"
}
]
},
{
"info": [
{
"value": "623",
"key": "customer.customerid"
},
{
"value": "1All Covered - Workspaces 1",
"key": "customer.customername"
}
]
}
]
}
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2020 12:10 AM
To get the length of Info:
var req = JSON_FILE;
var totalRecords = req["soap:Envelope"]["soap:Body"]["customerListResponse"]["return"].length;
To get the key and value in first "Info":
var key = req["soap:Envelope"]["soap:Body"]["customerListResponse"]["return"][0].info[0].key;
var value = req["soap:Envelope"]["soap:Body"]["customerListResponse"]["return"][0].info[0].value;
Thanks,
Raj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 04:24 AM
Hi Asifnoor,
I am not understanding. Can you please explain little bit more with example?
Thanks,
Rajesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2020 04:35 AM
Hello Raj,
It is difficult to parse the json string that you have shared, as it contains the following strings soap:Envelope, soap:Body.
So from wherever you are getting response, check if there is a possibility to get only return separately as a json string.
Otherwise, you need to do string operations and get the return outside of this string and then parse it.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2020 12:06 AM
Hi Asifnoor,
Thanks for your response. I find the way. Please see my above response.
Thanks,
Raj