xml-json-format

Convert xml string to neatly formatted JSON object


Keywords
xml, JSON, JavaScript
License
ISC
Install
npm install xml-json-format@1.0.8

Documentation

xml-json-format

Installation

USAGE

Run npm install --save xml-json-format

const toJSON = require('xml-json-format')

const xml = 
'<?xml version="1.0" encoding="utf-8"?>' +
'<note importance="high" logged="true">' +
'    <title>Happy</title>' +
'    <todo>Work</todo>' +
'    <todo>Play</todo>' +
'</note>';

const jsonResult = toJSON(xml);

console.log(jsonResult);

/* expected: {
    "_declaration": {
        "_attributes": {
            "version": "1.0",
            "encoding": "utf-8"
        }
    },
    "note": {
        "_attributes": {
            "importance": "high",
            "logged": "true"
        },
        "title": "Happy",
        "todo": [
            "Work",
            "Play"
        ]
    }
} */