Parsing JSON object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 09:21 AM
I would like to parse the below JSON format and then use the query which is mentioned in the first part to glide the records & update the value mentioned in the JSON second part to the table. How to parse this object?
{ "company.employeeIN1201222,100144334" : "IND",
"company.employee=12345^country=NULL" : "SING"}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 10:54 AM
@Ankur Bawiskar any input on this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 10:55 AM
Hi @imran rasheed ,
You can store these queries in an array using Object.keys(), please refer to the script below
var obj = {
"company.employeeIN1201222,100144334": "IND",
"company.employee=12345^country=NULL": "SING"
};
var objKeys = Object.keys(obj);
for (var i = 0; i < objKeys.length; i++) {
gs.print(objKeys[i]);
}
Output:
If my answer has helped with your question, please mark it as correct and helpful
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 12:36 AM
Hey Karan,
Thanks for the response, whereas how do you print the second part of country either its IND or SING.
Am storing the JSON in system property and trying to access it in the script by converting it using JSON parser.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2023 12:48 PM
Check this out:
https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/c_JSONAPI
Please mark my response as correct and helpful if it helped solved your question.
-Thanks