Skip to Content

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 and put the file in packages folder.

You can also grab the file at fast-xml-parser - Libraries - cdnjs . Just download the js file fxparser.min.js.

We test with version 5.2.3 of fast-xml-parser.

Step 2

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

parse-xml.js
/* @okjson.schemaVersion 1 @okjson.name 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 @okjson.author OK JSON @okjson.authorURL https://okjson.app */ $include('fxparser.min'); function main(string) { const parser = new XMLParser.default(); const result = parser.parse(string); const json = JSON.stringify(result, null, 4); $utility.viewInOKJSON(json); return ''; }

Step 3

Run the script and XML string as the input.