Logo

MonoCalc

/

XML to JSON Converter

Programming
Compact

XML input

JSON output

Put the cursor on any JSON value or XML node to see how the two line up.

Not covered by this tool

  • JSON to XML (the reverse direction) is a separate tool.
  • No XSD or DTD validation, DTD default attributes, XPath queries or XSLT.
  • HTML pages are usually not well-formed XML (<br> without a slash, &nbsp;).
  • Output doesn't copy xml2js, xmltodict or fast-xml-parser exactly; the options cover the common choices.
  • No loading from a URL. To convert an API response, paste it here. In browser devtools: Network → right-click the request → Copy response.
  • Files over 10 MB and streaming parsing aren't supported.

About This Tool

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, #text by 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/> become null, 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.

Large IDs stay strings
Integers beyond 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 &nbsp; 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.

Private by design
Parsing and conversion run entirely in your browser. Uploaded files are read locally, and the XML text is never stored or added to the page URL.

Frequently Asked Questions

Is the XML to JSON Converter free?

Yes, XML to JSON Converter is totally free :)

Can I use the XML to JSON Converter offline?

Yes, you can install the webapp as PWA.

Is it safe to use XML to JSON Converter?

Yes, any data related to XML to JSON Converter only stored in your browser (if storage required). You can simply clear browser cache to clear all the stored data. We do not store any data on server.

How does this XML to JSON converter work?

It parses your XML with a strict XML 1.0 parser that runs in the browser, then maps every element, attribute and text node to JSON using the convention you pick: Compact (objects keyed by element name) or Ordered (JsonML arrays). Put the cursor on any JSON value to see the XML that produced it.

Why do attributes start with @ in the JSON?

An attribute and a child element can share a name, as in <item id="1"><id>A</id></item>. The @ prefix keeps them apart. You can change the prefix or remove it in the options, but with no prefix a same-named attribute and element collide and the element is dropped.

Why is an element sometimes an object and sometimes an array?

XML doesn't say whether an element can repeat, so a feed with one <item> gives an object and a feed with two gives an array. Add the element to Always arrays for, or tick its box in the Structure tab, so it is always an array and your code sees one shape.

Why did 5.90 or 2.0 stay a string?

Safe conversion only turns text into a number when JSON would print exactly the same characters back, so 5.90 and version 2.0 stay text. Choose All numbers to convert them; the Notes tab then lists every value whose text changed, such as 5.90 becoming 5.9.

What is JsonML, and when should I use it?

JsonML writes each element as an array: the name, an optional attributes object, then its children in order. It keeps element order and mixed content such as <p>Hello <b>world</b></p>, so use it for XHTML, DocBook or any document where text and tags interleave.

Is my XML uploaded or stored anywhere?

No. Parsing and conversion run entirely in your browser, external entities and DTDs are never fetched, and the XML text is never saved or put in the URL. Only your option choices are remembered on this device.