Parsing JSON object

imran rasheed
Tera Contributor

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"}

11 REPLIES 11

imran rasheed
Tera Contributor

@Ankur Bawiskar any input on this?

Karan Chhabra6
Mega Sage
Mega Sage

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:

KaranChhabra6_0-1686851610796.png

 

If my answer has helped with your question, please mark it as correct and helpful

 

Thanks!

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.

Prateek kumar
Mega Sage

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