XML to JSON

Paste XML or drop a file. Ctrl+C copies the result.

How to convert XML and JSON

  1. Paste or open

    Paste XML into the Input pane, press Open to pick an .xml file, or drop it onto the pane. For the other direction, use the JSON to XML tab.

  2. Set the options

    Keep or drop attributes, turn numbers and booleans on or off, pick the indent and, for JSON to XML, the root element name and whether to add the declaration.

  3. Copy or download

    Press Copy, or Ctrl+C with nothing selected, to copy the whole result. Download saves data.json or data.xml.

Good to know

  • Text inside an element that also has attributes or children lands under the #text key.
  • With Numbers and booleans on, values that look like numbers become numbers. Turn it off to keep IDs with leading zeros as strings.
  • The input is validated first, so an unclosed tag shows its line and column rather than a half-converted result.
  • Files over 2 MB are read by the worker straight from disk. Only the first 1 MB of the result is drawn on screen; Copy and Download use the full output.

Questions people ask

How are attributes represented in JSON?

As keys that start with @_, next to the element's children, so <item id="7">Pen</item> becomes {"item": {"@_id": 7, "#text": "Pen"}}. Untick Attributes to drop them. The same prefix is read back when converting JSON to XML.

Why is a repeated element an array but a single one is not?

XML has no arrays, so the converter makes an array only when an element appears more than once under the same parent. A list with one item comes out as an object. Add a second item or handle both shapes in your code.

How do I get a root element when my JSON is an array?

Set the Root name. It wraps the output whenever the JSON is an array, a plain value, or an object with more than one top-level key, because XML needs exactly one root.

Are namespaces and CDATA handled?

Element names keep their prefix, such as soap:Body, and xmlns attributes appear as @_xmlns. CDATA sections are read as ordinary text. Comments and processing instructions are dropped.

Is my file uploaded?

No. Parsing and conversion run in a web worker inside your browser. Nothing is sent to a server.