XML to JSON Converter – See How Every Element Maps
APIs, RSS and Atom feeds, SOAP responses, sitemaps, Maven and Android config files still arrive as XML, while most application code wants JSON. This XML to JSON converter parses your document in the browser and turns it into JSON you can paste straight into JavaScript, Python or a test fixture. The rules aren't hidden: put the cursor on any JSON value and the XML element, attribute or text that produced it is highlighted in the input, and the other way round.
Why XML doesn't map to JSON one to one
JSON has objects, arrays, strings, numbers, booleans and null. XML has elements, attributes, text, CDATA, comments, namespaces and mixed content, and it never says whether an element may repeat. Every converter has to make choices, and this tool shows them:
- Attributes become keys with a prefix, so
<price currency="USD">gives"@currency": "USD". The prefix keeps an attribute apart from a child element with the same name. - Text next to attributes goes under a text key,
#textby default. An element with only text becomes a plain value. - Repeated siblings become arrays. One
<item>gives an object, two give an array, which is the classic cause of code that works on one feed and breaks on the next. - Empty elements such as
<tags/>becomenull, an empty string or an empty object.
Compact or Ordered (JsonML)
The Compact convention produces the object-shaped JSON most people expect from an xml2json tool. It groups children by name, so the relative order of different elements is lost. The Ordered convention follows JsonML: each element is an array of its name, an optional attributes object and its children in document order, so <p>Hi <b>there</b></p> becomes ["p","Hi ",["b","there"]]. Use it for XHTML, DocBook and other documents where text and tags interleave. The mapping preview in the options panel shows what each setting does to four small snippets as you change it.
Fixing the array problem
The Structure tab lists every element path with its count and how many times it appears under each parent. A path that is single in one place and repeated in another gets a warning, and its Always array box adds the path to the Always arrays for list. Entries can be a bare name such as item, matched anywhere, or an exact path such as rss/channel/item. Your option choices are remembered on this device, so the same feed gives the same JSON shape every time.
Safe number and boolean conversion
Turning text into numbers is where most XML to JSON converters silently change data. In Safe mode a value becomes a number only when JSON would print exactly the same characters, so 44.95 converts but a price of 5.90, a version of 2.0 and a zip code of 02134 stay text. Only lower-case true and false become booleans, text is never turned into null, and CDATA content is never retyped. All numbers converts more and lists every value whose text changed.
9007199254740991, such as tweet or order IDs, can't be stored exactly in a JavaScript number. They stay strings in every mode so no digits are lost.Notes to check before you trust the JSON
The Notes tab flags paths that are sometimes arrays, fields that converted to different types in different places, mixed content and interleaved elements whose order Compact mode loses, undeclared namespace prefixes, key collisions, and dropped comments or processing instructions. Each note has a Jump to button that selects the first instance in the input.
Strict parsing with clear errors
The tool includes its own XML 1.0 parser, so errors read the same in every browser and give an exact line and column, for example a mismatched end tag, an unescaped &, or an HTML entity such as that XML doesn't define (with the numeric reference to use instead). Entities declared in an internal DOCTYPE are expanded, while external entities are never loaded and entity expansion is capped, which makes XXE and "billion laughs" payloads harmless.