/xml-json

Primary LanguageTypeScript

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"
        ]
    }
} */