- Shall we take into account XML or XML Schema (see issues below)
- TD issue #139
- SAP guidelines for XML
- NPM Libraries
- MOST of the libs support one-way only, we need bi-directional
- https://www.npmjs.com/package/xml2json -> bidirectional (Last updated 3 years ago) -> tested: does not seem to work properly
- https://www.npmjs.com/package/jxon -> bidirectional (Last updated 6 years ago) -> tested: works better
- https://github.com/nashwaan/xml-js -> bidirectional (Last updated4 years ago) -> to be tested!
- https://github.com/Leonidas-from-XIV/node-xml2js -> bidirectional (Last updated 3 years ago) -> to be tested!
- https://github.com/buglabs/node-xml2json -> bidirectional (Last updated 4 years ago) -> to be tested!
- https://github.com/NaturalIntelligence/fast-xml-parser -> bidirectional (Last updated 1 month ago) -> Works GREAT!
- https://www.freeformatter.com/xml-to-json-converter.html
- https://codebeautify.org/xmltojson
- https://www.utilities-online.info/xmltojson OR https://www.utilities-online.info/jsontoxml
- https://www.convertjson.com/xml-to-json.htm
- http://badgerfish.ning.com/
- Related Tools / Information / Links
- JSON members whose names start with
@
(or$
) are transformed to XML attributes (TBD) #text
(or_
) used for text content (TBD)- Simple types are always nested in a term
- What about namespaces?
Multiple roots NOT possible in XML -> add outer root?Starting with XML this should not be an issueneed to always wrap JSON in root?Starting with XML this should not be an issue
e.g., for reading XML int using JSON in scripts that then get converted to XML on the wire
XML | JSON | |
---|---|---|
<foo>1</foo> |
-> | {"foo": "1"} |
<root att="X">1</root> |
-> | {"root": {"@att": "X", "#text": "1"}} OR {"root":{"$att":"X","_":"1"}} |
<root><a>A</a><b>B</b></root> |
-> | {"root": {"a": "A", "b": "B"}} |
<root><a>A1</a><b>B1</b><a>A2</a><b>B2</b></root> |
-> | {"root": {"a": ["A1", "A2"], "b": ["B1", "B2"]}} OR {"root": [{"a": "A1","b": "B1"},{"a": "A2","b": "B2"}]} |
XML schema could tell that there can be multiple a+b sequences. Returning from JSON to XML might result in different result (first a's and then b's which is not the same). | ||
<root at="dd"><a>A1</a><a>A2</a><b>B1</b><b>B2</b></root> |
||
<nsX:Name xmlns:nsX="http://mycompany">Widget A</nsX:Name> |
-> | {"nsX:Name":{"$xmlns:nsX":"http://mycompany","_":"Widget A"}} |
... | -> | ... |
e.g., for using JSON in scripts that then get converted to XML on the wire
Note: ONLY specific JSON can be transformed to XML (see some fail below).
JSON | XML | |
---|---|---|
"string" |
-> | |
{"el": 123} |
-> | <el>123</el> |
{"el": 123, "@at": true} |
-> | <el at="true">123</el> ??? at on this level or outside in root ??? Sample not valid, needs outer nesting for @? --> Fail |
{"el1": 1, "el2": 2, "@at": true} |
-> | <root at="true"><el1>1</el1><el2>2</el2></root> root added because there cannot be multipe roots in XML!?! |
{"root":{"$att":"X","_":"1"}} |
-> | <root att="X">1</root> |
{"nsX:Name":{"$xmlns:nsX":"http://mycompany","_":"Widget A"}} |
-> | <nsX:Name xmlns:nsX="http://mycompany">Widget A</nsX:Name> |
... | -> | ... |