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 09:11 PM
what script did you try so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 12:51 AM
{"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"}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 01:54 AM
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?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 02:03 AM
We store this in system property and call into the script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 02:15 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader