Skip to content
toolsdocks

Convert JSON to XML

Paste JSON and get formatted XML, with a clear error if the JSON is invalid. This page opens the formatter with XML and From JSON selected.

Runs on your device

More options in the full YAML and XML formatter and validator.

Loading tool…

How to convert JSON to XML

  1. Paste JSON or choose a .json file.
  2. Leave the mode on From JSON and the language on XML (preselected here).
  3. Read the XML in the output and pick the indentation you want.
  4. Copy it or download converted.xml.

Worked example

{"book":{"title":"Dune"}} becomes an XML declaration followed by a book element holding a title element with the text Dune. The output downloads as converted.xml.

Formats and limits

InputJSON
OutputXML
Enginejs-yaml (YAML 1.2) and fast-xml-parser with validator

Limitations

  • XML needs one root element, so JSON with several top-level keys or a top-level array is wrapped in <root>.
  • Numbers, true and false become element text; XML has no number type.
  • null and empty strings become empty elements.
  • Output is limited to 50 MB.

Questions

How are arrays written?

An array of values or objects under a key becomes repeated elements with that key's name. A top-level array, or JSON with several top-level keys, is wrapped in a root element, and the tool says so.

How do I write XML attributes?

Prefix the key with @_ to make an attribute and use #text for an element's text, the same convention used when XML is converted to JSON. {"book":{"@_id":"7","title":"Dune"}} gives <book id="7"> with a title element.

It says a key is not a valid element name.

XML names start with a letter or underscore and contain no spaces. The key is named in the message; rename it in the JSON, for example first_name instead of first name.

Is my JSON uploaded?

No. The text is converted in your browser and nothing is uploaded.

Privacy

Runs on your device. Files and text are processed in this browser tab and are not uploaded.

This page opens the YAML and XML formatter and validator ready for this task. See the privacy policy for how toolsdocks handles data.