Parse XML with OK JSON

Build a script to parse XML and view the structure in OK JSON.

Getting Started

Step 1

Download fast-xml-parser (opens in a new tab) and put the file in packages folder.

You can also grab the file at fast-xml-parser - Libraries - cdnjs (opens in a new tab). Just download the js file fxparser.min.js.

Step 2

Create a script file in the script folder with the following code.

@okjson.schemaVersion 1 Parse XML
@okjson.description Parse XML, convert to JSON, and view in OK JSON.
@okjson.icon chevron.left.forwardslash.chevron.right
@okjson.preprocessInput no
@okjson.openResultInNewWindow no OK JSON
function main(string) {
  const parser = new XMLParser();
  const result = parser.parse(string);
  const json = JSON.stringify(result, null, 4);
  return '';

Step 3

Run the script and XML string as the input.