JSON to XML Converter
Paste text or open a file in either box to turn legacy XML into JSON or JSON into valid XML with a declaration, with clear rules for attributes, text, and repeated elements.
When converting XML to JSON, plain numbers and lowercase true and false in element text and attribute values become numbers and booleans. Numbers that start with 0, like 007, and integers beyond the exact range stay strings. Turn it off to keep everything as strings.
How to Use
- Paste JSON into the top box to get XML below, or paste XML into the bottom box to get JSON above. No direction switch needed. XML output always starts with an XML declaration (<?xml version="1.0" encoding="UTF-8"?>).
- XML to JSON rules: an element's attributes become keys starting with @, so id="1" turns into "@id": 1. When an element has attributes or child elements, its text goes under the "#text" key; with neither, the element's value is just the text. CDATA counts as ordinary text, an empty element is an empty string, and namespace prefixes and xmlns declarations are kept as-is in key names, such as "ns:item" and "@xmlns:ns". Whitespace around element text is trimmed, and indentation-only whitespace isn't text.
- Sibling elements with the same name become an array, and an element that appears once becomes an object or text. If the same name repeats in some places and appears only once in others, the tool warns you, since code reading the result has to handle both an array and a single value.
- JSON to XML rules: when the top level has exactly one key (and its value isn't an array), that key is the root element; otherwise everything is wrapped in a root element with a warning. A top-level array goes inside root with each entry as an item element. Arrays become repeated elements of the same name, keys starting with @ become attributes, #text becomes the element's text, and null becomes an empty element.
- A key that isn't a valid XML name (for example one with a space or slash) has its illegal characters replaced with underscores, and a key starting with a digit or hyphen gets an underscore in front. Each gets a warning with its path, while a colon in a namespace prefix is kept as-is. Control characters XML doesn't allow are replaced with U+FFFD with a warning.
- XML comments and processing instructions (other than the XML declaration) aren't kept, and mixed content, where text and child elements are interleaved, loses its relative order. Both produce warnings. Custom entities declared in a DOCTYPE are not expanded; only the five built-in XML entities and numeric character references are decoded.
- XML to JSON detects numbers and booleans by default: plain numbers and lowercase true and false in element text and attribute values become real types, while numbers that start with 0, like 007, and integers beyond the exact range stay strings. Turn off “Detect numbers and booleans” to keep every value a string. Indentation can be 2 spaces, 4 spaces, Tab, or minified, and applies to both outputs; “Sort keys” orders every object's keys and leaves arrays alone.
- You can also click “Choose a file” or drop a file (up to 5 MB) into either box. .json, .jsonc, and .json5 files go into the JSON box and .xml files into the XML box, and the conversion runs immediately. Non-UTF-8 files fall back to Windows-1252 on English pages, and you can switch the encoding manually. Each box's “Download” button keeps the original base name with .json or .xml, or uses data.json / data.xml for pasted text.
- Syntax errors show the line and column, quote the source line with a ^ marker, and keep the other box's last valid output.
- For other pairs, such as YAML to TOML or CSV to XML, use the Data Format Converter: pick any two of JSON, YAML, TOML, INI, .env, properties, CSV, and XML for its two boxes. You'll find it in the related tools below this page.
JSON to XML and XML to JSON: Input and Output
Paste JSON into the top box and the XML appears in the bottom box. Paste XML into the bottom box and the JSON appears above. Here are three examples with the exact output.
JSON to XML. Keys that start with @ become attributes. Input:
{"note":{"@id":"1","to":"Ann","body":"Hi"}}
Output:
<?xml version="1.0" encoding="UTF-8"?>
<note id="1">
<to>Ann</to>
<body>Hi</body>
</note>
An array becomes repeated elements. Input {"list":{"item":["a","b"]}} gives:
<?xml version="1.0" encoding="UTF-8"?>
<list>
<item>a</item>
<item>b</item>
</list>
XML to JSON. Input <price currency="USD">120</price> gives:
{
"price": {
"@currency": "USD",
"#text": 120
}
}
The Rules at a Glance
| In XML | In JSON |
|---|---|
An attribute such as id="1" |
A key starting with @, such as "@id": 1 |
| Text in an element that also has attributes or children | The "#text" key |
| Text in an element with neither | The value itself |
| Sibling elements with the same name | An array |
| An element that appears once | An object or text |
The conversion runs in your browser, and indentation is 2 spaces by default. You can switch to 4 spaces, Tab, or minified.
FAQ
How do I convert JSON to XML online?
Paste your JSON into the top box and the XML appears in the bottom box right away, starting with an XML declaration. There is no convert button and no direction to pick. To go the other way, paste XML into the bottom box and the JSON appears above. An example is further down the page.
Is my JSON or XML uploaded or saved?
No. The conversion runs in your browser, and a file you open or drop is read on your own device too. Only your display choices, such as indentation, sorted keys, and number detection, are saved on this device, never the content you paste.
How do I read XML attributes and text after converting to JSON?
Attributes always become keys starting with @, and text becomes #text. For example <price currency="USD">120</price> becomes {"price": {"@currency": "USD", "#text": 120}}, so in code you read price["@currency"] and price["#text"]. If an element has neither attributes nor children, such as <name>Tempura</name>, it's simply {"name": "Tempura"} with no extra #text level. The rules are fixed, and converting back turns @ and #text into attributes and text again.
Why do some elements become arrays while others stay single values?
XML has no array syntax, so repeated elements are the only signal: two or more sibling elements with the same name become an array, and a single one becomes an object or text, because one document can't tell whether it's really a list that happens to have one entry. That forces the code reading the result to handle both shapes, so when the same name repeats in some places and appears once in others, the tool warns you and points to one of the single occurrences. To get a fixed array, wrap single values into an array in your code.
What happens when the JSON top level has several keys, or is an array?
XML needs exactly one root element. When the JSON has exactly one top-level key and its value isn't an array, that key is the root, so {"note": {...}} becomes <note>…</note>. With several keys, an empty object, a single value, or an array, everything is wrapped in a root element with a warning: multiple keys become children of root, and each array entry becomes an item element. Converting back keeps that root level, because the tool can't know it was added automatically.
What happens to key names with spaces or leading digits, and to null and empty arrays?
XML element names can't contain spaces or start with a digit, so "first name" becomes first_name and "2nd" becomes _2nd, each with a warning naming its path. A colon is a legal name character, so namespace prefixes like ns:item are kept as-is. null becomes an empty element, and an empty array also becomes one empty element; both come back as an empty string in JSON, not null or an empty array, and each gets a warning.
How are XML comments, CDATA, DOCTYPE, and custom entities handled?
Comments and processing instructions (such as <?xml-stylesheet?>) aren't kept, and you get one warning; the XML declaration itself isn't a processing instruction and doesn't warn. CDATA is treated as ordinary text, with its < and & kept literally as content. Custom entities declared in a DOCTYPE are not expanded, which also rules out entity-expansion attacks that blow up the input, and &name; stays as written. Only the built-in < > & " ' and numeric references like A and A are decoded.
Why does a tag named constructor or __proto__ fail to convert?
The library this tool uses to parse XML refuses tags named __proto__, constructor, or prototype to prevent prototype pollution. The tool points to the position and asks you to rename it first. JSON to XML can still write such a name, but reading it back is refused in the same way. Attribute names aren't affected.
Related Tools
Data Format Converter
Pick a data format for each box and convert between any two of JSON, YAML, TOML, INI, .env, properties, CSV, and XML, such as application.properties to YAML, .env to JSON, or CSV to XML. Anything lost along the way is flagged one by one, all in your browser.
JSON to YAML Converter
Paste into either box to convert JSON to YAML or YAML back to JSON. Big numbers stay exact, and every lost detail gets its own warning.
JSON to TOML Converter
Paste text or open a file in either box to convert between JSON and TOML (including pyproject.toml and Cargo.toml), with per-path warnings for any lost details.
JSON to CSV Converter
Paste text or open a file in either box to convert between a JSON array and CSV. Nested fields are flattened with a warning, and downloaded CSV gets a BOM so Excel shows non-English text correctly.
HTML Entity Encoder & Decoder
Type in either box to turn text into HTML entities, or decode < & 中 and other entities back into text. All named entities supported.
JSON Formatter
Paste one long line of JSON and get it neatly laid out at once. Pick 2-space, 4-space, or tab indentation, or minify it to one line, sort keys, and check the syntax. Big numbers stay exact, and formatting never changes a value.
Unicode Escape Encoder & Decoder
Type in either box to turn text into \uXXXX, \u{…}, &#x…;, or U+XXXX, or decode any mix of Unicode escapes back into text.
Base64 Encoder & Decoder
Type in either box to encode text as Base64 or decode Base64 back into text. UTF-8 safe, with a URL-safe alphabet option.