3tej home

What is JSON to XML Converter?

A JSON to XML Converter converts JSON into XML directly in your browser. It parses the source format, applies the standard mapping or formula, and outputs the target format ready to copy. Developers use it when debugging APIs and preparing data files.

JSON to XML Converter

Convert JSON to XML in your browser. Pretty-printed output.

🔒 Browser-only ⚡ Instant 💸 Free forever 📡 Works offline 🚫 No signup
← Utilities

TLDR

Paste JSON, click Convert. The tool walks the JSON tree and emits XML with 2-space indentation. The root element name defaults to 'root'; nested objects become child tags; arrays become repeated tags.

Runs entirely in your browser. No upload, no signup, no logging. Output is for personal or commercial use; we don't claim any rights.

About converting JSON to XML

JSON and XML are the two dominant text formats for structured data, and you frequently need to move between them. JSON (JavaScript Object Notation) is compact and maps directly onto objects and arrays, which is why modern web APIs default to it. XML (Extensible Markup Language) is more verbose but carries attributes, namespaces, schemas, and a long legacy of enterprise tooling, so SOAP services, configuration files, RSS feeds, and many financial and government systems still demand it. This converter takes valid JSON and emits clean, indented, well-formed XML so you can feed JSON data into an XML-only consumer.

There is no single official JSON-to-XML standard, because the two data models do not line up perfectly. JSON has ordered arrays and a handful of primitive types; XML has elements, attributes, text nodes, and exactly one root. Any converter therefore picks a convention for the awkward cases. This tool uses the widely adopted rules below: object keys become element tags, arrays become repeated tags, and a special @attributes key becomes XML attributes.

How the JSON to XML mapping works

The converter parses your input with the browser's native JSON parser, then walks the resulting tree and writes an XML string with two-space indentation.

object key      -> <key>...</key>        (one element per key)
array [a, b]    -> <key>a</key><key>b</key>  (repeated tag)
"@attributes"   -> attributes on the parent element
string / number -> escaped text inside the element
null            -> self-closing <key/>
single root key -> used as the root; else wrapped in <root>
  • Objects recurse: every nested object produces nested child elements.
  • Arrays repeat the parent tag, because XML has no native list type.
  • Attributes come from the @attributes convention, a pattern popularised by common json2xml libraries.
  • Escaping handles the five XML predefined entities so the output is always valid.

Worked example

Paste this JSON, which has a single root key, an array of users, and an id attribute:

{"root":{"user":[{"@attributes":{"id":"1"},"name":"Alice"},
                  {"@attributes":{"id":"2"},"name":"Bob"}]}}
  1. Root: the single top-level key root becomes the root element.
  2. Array: the two user array items each emit a separate <user> tag.
  3. Attributes: each @attributes object becomes id="1" and id="2" on the user tags.
  4. Text: the name values become child elements with escaped text.

The output is well-formed XML you can hand straight to any parser:

<?xml version="1.0" encoding="UTF-8"?>
<root>
  <user id="1">
    <name>Alice</name>
  </user>
  <user id="2">
    <name>Bob</name>
  </user>
</root>

JSON to XML mapping reference

JSON constructXML outputNotes
{"a": "x"}<a>x</a>Key becomes tag
{"a": {"b": 1}}<a><b>1</b></a>Nested objects recurse
{"a": [1, 2]}<a>1</a><a>2</a>Array repeats the tag
{"a": null}<a/>Self-closing element
{"@attributes": {"id": "1"}}id="1"Becomes an attribute
{"a": "<b>"}<a>&lt;b&gt;</a>Special chars escaped

Common pitfalls

  • Multiple top-level keys. XML allows only one root. If your JSON has several top-level keys, wrap them in a single outer object first, or the converter adds a synthetic <root>.
  • Keys that are not valid XML names. XML element names cannot start with a digit or contain spaces. A JSON key like "123" or "first name" produces invalid XML; rename the key before converting.
  • Expecting a perfect round trip. Because JSON and XML data models differ, converting JSON to XML and back will not always reproduce byte-identical JSON. Type information (number versus string) is lost in XML, which stores everything as text.
  • Forgetting the @attributes convention. Without it, every value becomes a child element. If you need attributes, structure your JSON with the @attributes key.
  • Invalid JSON in, no XML out. The tool does not repair malformed JSON. A trailing comma or unquoted key triggers a parse error rather than guessing your intent.

When you would use this

Feeding legacy systems

Push JSON API data into a SOAP, RSS, or XML-config consumer.

Debugging APIs

Inspect how a JSON payload maps onto an XML structure.

Test fixtures

Generate valid XML samples from compact JSON definitions.

Learning

See exactly how the object, array, and attribute rules behave.

Frequently asked questions

How are JSON objects and arrays mapped to XML?

Each key in a JSON object becomes an XML element whose tag name is the key and whose content is the converted value. A JSON array becomes a repeated element: the parent key is emitted once per array item, so {"item":[1,2]} produces two <item> tags rather than a single tag containing a list. Nested objects recurse, producing nested child elements with two-space indentation.

How do I create XML attributes from JSON?

This converter uses the common @attributes convention: a key named @attributes holding an object is emitted as attributes on the parent element rather than as child tags. For example {"user":{"@attributes":{"id":"1"},"name":"Alice"}} becomes <user id="1"><name>Alice</name></user>. There is no single official JSON-to-XML standard, so the @attributes key is a widely used pattern from libraries like the PHP json2xml family.

What happens to the root element?

XML requires exactly one root element, but JSON can have multiple top-level keys. If your JSON has a single top-level key, the converter uses that key as the root tag. If it has several keys or is an array, the converter wraps everything in a synthetic <root> element so the output is well-formed. Wrapping your JSON in one outer object before converting gives you control over the root name.

Are special characters escaped in the XML output?

Yes. The five XML predefined entities are escaped automatically: ampersand becomes &amp;, less-than becomes &lt;, greater-than becomes &gt;, and double quotes become &quot; inside attribute values. This keeps the output valid even when your JSON string values contain characters that would otherwise break the XML, so you can paste the result directly into an XML parser.

Is the conversion done in my browser?

Yes. The JSON is parsed with the browser's native JSON.parse and walked into an XML string entirely on your device. Nothing is uploaded, logged, or stored, and after the first load the page works offline. You can confirm by watching the Network tab in developer tools: no requests fire during a conversion beyond the initial page and asset load.