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:46 PM
Hi Imran,
Please refer to below video where it has been explained in detail.
Please mark this comment as Helpful/Correct Answer if it helped you.
Cheers,
Hardit Singh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 01:56 AM
HI @imran rasheed ,
Hope you are doing great.
Try using below script for reference to parse the json and store it in json:
var parsedObject = JSON.parse(jsonObject);
for (var key in parsedObject) {
if (parsedObject.hasOwnProperty(key)) {
var query = key;
var value = parsedObject[key];
// Use the query and value to glide records and update the table
var gr = new GlideRecord(table);
gr.addEncodedQuery(query);
gr.query();
while (gr.next()) {
gr.setValue("field_name", value);
gr.update();
}
}
}
Regards,
Riya Verma