Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Parse YAML Files In ServiceNow?

Tom Rausch
Tera Guru

How can I parse YAML files in ServiceNow?

 

Example

ServiceNow has an integrated JSON parser.

For example, from various posts, I can retrieve a JSON file via REST, then parse it with the JSON object.

    var restMessage = new sn_ws.RESTMessageV2('Rest Integration', 'GET');
    var response = restMessage.execute();
    var responseBody = response.getBody();
    var httpStatus = response.getStatusCode();
    var parsedData = JSON.parse(responseBody) 

What if the "responseBody" is in YAML format? Can I parse it with a similar YAML object?

    var restMessage = new sn_ws.RESTMessageV2('Rest Integration', 'GET');
    var response = restMessage.execute();
    var responseBody = response.getBody();
    var httpStatus = response.getStatusCode();
    var parsedData = YAML.parse(responseBody)
1 ACCEPTED SOLUTION

Tom Rausch
Tera Guru

The application YAML JSON Converter in the ServiceNow Store is a solution. This application converts data in YAML format to JSON.

TomRausch_0-1697745323636.png

 

 

View solution in original post

3 REPLIES 3

Tom Rausch
Tera Guru

The application YAML JSON Converter in the ServiceNow Store is a solution. This application converts data in YAML format to JSON.

TomRausch_0-1697745323636.png

 

 

Hi I cannot download from servicenow store 

can you suggest steps here to download YAML to JSON converter

Use this, as it also allows for encoding back into YAML.
https://github.com/nodeca/js-yaml

'Install' it as a Script Include. If you're unsure how to load this into SN, ask ChatGPT.  And consider the difference of it being loaded globally each time into memory, and on demand (initialise). As it's a large file.