Skip to content
Toolew.com

JSON to XML Converter

Convert JSON to well-formed XML, mapping arrays to repeated elements and @-prefixed keys to attributes, with safe element names.

Runs in your browser. Your data is not uploaded.
Loading tool…

This guide is not yet available in your language and is shown in English.

Tool guide

What this tool does

JSON to XML Converter produces indented, well-formed XML from any JSON document. Choose the root and array item element names, which keys become attributes and which key holds element text, add an XML declaration and mark null values with xsi:nil. Keys that are not legal XML names are made safe automatically and special characters are escaped.

Plenty of systems still exchange XML: SOAP services, RSS feeds, banking and government interfaces, office formats and many enterprise integrations. JSON and XML do not map one to one, though. XML needs a single root element, has attributes as well as child elements, cannot use names that start with a digit or contain spaces, and has no native array, so a list has to become repeated elements.

This converter applies the widely used conventions for that mapping. A key holding an array produces one element per item, so { "book": [a, b] } becomes two <book> elements. Keys beginning with the chosen prefix, such as @id, become attributes, and a #text key supplies the element’s text when it also has attributes. When the JSON has several top-level keys, or is an array, a root element wraps it. Invalid characters in names are replaced with underscores, and &, < and > in values are escaped. It runs locally using fast-xml-parser.

How to use JSON to XML Converter

  1. Paste JSON into JSON input, or click Sample to see attributes, arrays and text nodes in action.
  2. Set the Root element name and the Element name for array items.
  3. Choose which keys become attributes, for example keys starting with @, and the key used for element text.
  4. Pick the Indentation, and toggle the XML declaration and self-closing empty elements.
  5. Optionally mark null values with xsi:nil so XML Schema validators read them as nil.
  6. Copy the XML or download data.xml; convert several JSON files at once in batch mode.

Tips for better results

  • Use the same prefix your XML to JSON tool produced (@ or @_) to round-trip documents without losing attributes.
  • If the JSON has exactly one top-level key, that key becomes the root and no extra wrapper is added.
  • Arrays nested directly inside arrays are wrapped in item elements, because XML has no other way to express a list of lists.
  • Validate the result with XML Formatter, which also reports the line and column of any problem.

Common use cases

  • Building a request body for a SOAP or legacy XML API from JSON test data.
  • Producing an XML product feed or sitemap-like file from a JSON export.
  • Supplying sample XML to colleagues who maintain XSLT or XML Schema files.
  • Migrating configuration from a JSON-based tool to an XML-based one.

Common mistakes to avoid

  • Expecting a specific XML Schema to be satisfied automatically; element order and namespaces must still match what the schema requires.
  • Using keys with spaces or leading digits and being surprised by renamed elements such as _2024 or first_name.
  • Giving a nested object to an attribute key; attributes can only hold plain values, so such keys are written as elements instead.

Frequently asked questions

How are JSON arrays represented in XML?

An array under a key repeats that element once per item. A top-level array, or an array inside another array, is wrapped in the root element and uses the item element name you choose.

How do I create XML attributes?

Prefix the key with the chosen marker, for example "@id": "bk101", and it becomes id="bk101" on the parent element. Attribute values must be strings, numbers, booleans or null.

What happens to null values?

By default they become empty elements, written as self-closing tags. With Mark null values with xsi:nil switched on, they carry xsi:nil="true" and the XML Schema instance namespace is declared on the root.

Are special characters escaped?

Yes. Ampersands and angle brackets in text and attribute values are written as entities such as &amp; and &lt;, so the output is always well-formed.

Feedback & suggestions

Help us improve JSON to XML Converter. We read every message.

Rating (optional)
Necessary
Required for security, language and theme preferences. Always on.