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

Community Alums
Not applicable

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

 

Riya Verma
Kilo Sage
Kilo Sage

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();
    }
  }
}

    
Please mark the appropriate response as correct answer and helpful, This may help other community users to follow correct solution.
Regards,
Riya Verma