XML ↔ JSON Converter
Convert XML to JSON and back, with attributes as @ keys and text as #text.
Use the direction buttons to choose XML to JSON or the reverse, paste your input, and the result appears after about half a second. The xml-js 1.6.11 library does the work; only its file is downloaded from a CDN on first load, and your data stays in the page.
| XML | JSON |
|---|---|
<book category="fiction"> <title lang="en">Harry Potter</title> <year>2005</year> </book> | {
"@category": "fiction",
"title": {
"@lang": "en",
"#text": "Harry Potter"
},
"year": 2005
} |
Attributes get an @ prefix, and text that sits next to attributes goes to #text. An element that repeats becomes an array, but a single one stays an object, so receiving code may need to wrap it. Text that reads as a number, true or false takes that type, so 2005 is a number and a zip code 01234 becomes 1234; fix such values to strings in the JSON. The <?xml ?> declaration is always dropped.
The reverse direction accepts the same notation. {"user": {"@id": "7", "#text": "kim"}} gives <user id="7">kim</user>, and the original xml-js names _attributes and _text work too. Several top-level keys produce XML with several roots, so wrap them in one key.
Compact, Ignore Comments (on by default) and Trim take effect only after you press Convert. A conversion error is usually a missing closing tag or an & not written as &; the message gives the line and column.