how can i read Json data for specific parameters

Emp 53
Tera Contributor

Hi Team,

Below is the JSON data updated in 1of the variables in catalog item.

{

"id":"123",

"region":"us-east-1",

"name":"123@gmail.com"

} i above JSON i need to read id & name details. how can i develop script for the same.

8 REPLIES 8

Sandeep Rajput
Tera Patron
Tera Patron

@Emp 53 Here is how you should do it.

 

var ritm = 'RITM0010014'; //Replace with RITM number
var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', ritm);
gr.query();
var jsonVar='';
while(gr.next()) {
	jsonVar = JSON.parse(gr.variable.variable_name); //replace variable name with variable containing JSON data
       gs.info(jsonVar.id);//will print id
       gs.info(jsonVar.name);//will print name
      gs.info(jsonVar.region);//will print region
}

 

Hope this helps.

Hi @Sandeep Rajput,

Tried That bit received below error

 

Evaluator: com.glide.script.RhinoEcmaError: Unexpected token: u
   script : Line(155) column(0)

@Emp 53 Could you post your script here.

var gr = new GlideRecord('sc_req_item');
gr.addQuery('number', 'RITM1100611');
gr.query();
var jsonVar='';
while(gr.next()) {
    jsonVar = JSON.parse(gr.variables.bulk_info); //replace variable name with variable containing JSON data
       gs.print('id: '+jsonVar.id);//will print id

}