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

Ankur Bawiskar
Tera Patron
Tera Patron

@imran rasheed 

what script did you try so far?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

{"encodedquery" :  "company.employeeIN1201222,100144334" ,"country" : "IND"}
When I have the format like this, I am able to parse with below script

var parser = new JSONParser();
var parsed = parser.parse(jsonString);
var query = parsed.encodedquery;
var country = parsed.country;

 

How to do parsing here, where I need to split the encoded query & country and then use it in script to update record.

{ "company.employeeIN1201222,100144334" : "IND",

"company.employee=12345^country=NULL" : "SING"}

@imran rasheed 

the json key is changing everytime

So how will you know what key to use for parsing everytime

From where are you receiving this json?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

We store this in system property and call into the script.

@imran rasheed 

so you are storing the json in system property and where do you wish to use it?

can you share the relevant scripts?

are you saying you will use different encoded query for different country/region i.e. IND, SING etc

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader