ServiceNow Tools · LessonReviewed by Neelima, ServiceNow Architect · Updated · Published · current release · utility
ServiceNow XML / JSON formatter
Pretty-print payloads while building integrations.
Quick answer
REST integration work means reading raw payloads constantly, so format and validate them here and log them from script: JSON.stringify(obj, null, 2) inside gs.info() pretty-prints an object to the system log, and JSON.parse(request.body.dataString) turns an inbound body into an object you can read fields from in a Scripted REST API.
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);
Try it YourselfJavaScript
▸ Press Run to execute.
Runs in a sandbox in your browser. Mock gs and GlideRecord and sample data are provided.
Practise this on your own free instance.