Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

JSON Parse

Sven Olsen
Tera Contributor

Hi 

 

I have simple question. What is the difference between both parsing ways? Output is the same.

 

 

var jsonString = '{"var1": "hello","var2":"world"}';
var parsed = JSON.parse(jsonString);
gs.info(parsed.var1)

 

 or 

 

var jsonString = '{"var1": "hello","var2":"world"}';

var parser = new JSONParser();
var parsedData = parser.parse(jsonString);

gs.info(parsedData.var1)

 

1 ACCEPTED SOLUTION

Aman Kumar S
Kilo Patron

Both can be used to parse a JSON object, and both are present as script includes, you can also check for yourself to better understand this.

Although, JSON Parser that does not use javascript's eval() function. Safe and secure. It does not check for the validity of the JSON string, but shouldn't create any catastrophic errors.

Best Regards
Aman Kumar

View solution in original post

1 REPLY 1

Aman Kumar S
Kilo Patron

Both can be used to parse a JSON object, and both are present as script includes, you can also check for yourself to better understand this.

Although, JSON Parser that does not use javascript's eval() function. Safe and secure. It does not check for the validity of the JSON string, but shouldn't create any catastrophic errors.

Best Regards
Aman Kumar