XML / JSON formatter
Quick answer
When building REST integrations you constantly read raw payloads. Format and validate them, and log them from script.
Key takeaways
- Pretty-print JSON in script
- Parse an inbound body
When building REST integrations you constantly read raw payloads. Format and validate them, and log them from script.
Pretty-print JSON in script
var obj = { number:'INC0010023', priority:1 };
gs.info(JSON.stringify(obj, null, 2));Parse an inbound body
var data = JSON.parse(request.body.dataString); gs.info(data.short_description);
Want to learn this properly?
Our live, instructor-led ServiceNow Training covers this hands-on, with real projects and a certification path.
Check your understanding
Which pretty-prints an object with indentation?
- A. JSON.stringify(obj, null, 2)
- B. JSON.parse(obj)
- C. gs.print(obj)
Show answer
A. JSON.stringify(obj, null, 2)
The third argument sets indentation.
Which turns a JSON string into an object?
- A. JSON.parse()
- B. JSON.stringify()
- C. GlideRecord()
Show answer
A. JSON.parse()
JSON.parse deserialises a string.
Frequently asked questions
What does the term XML / JSON formatter refer to in ServiceNow?
When building REST integrations you constantly read raw payloads. Format and validate them, and log them from script.