JSON to XML Converter
Turn JSON into well-formed XML with explicit rules for roots, arrays, attributes and text.
JSON input
XML output
Paste JSON to generate XML
Results update as you type. Nothing leaves your browser.
Details
This tool builds well-formed XML from JSON entirely in your browser. Choose the root element and array item tag, decide whether arrays get a wrapper, promote @-prefixed keys to attributes, and use #text for element content alongside attributes. Non-ASCII names and text stay intact, invalid names are mapped to field_N with a visible report, and XML-illegal control characters are rejected instead of silently producing broken XML. Copy or download the complete document with your chosen indentation and an optional XML declaration.
More examples
Object to nested elements
// JSON
{
"id": 42,
"user": { "name": "Ada Lovelace", "roles": ["admin", "dev"] },
"active": true
}
// XML
<?xml version="1.0" encoding="UTF-8"?>
<root>
<id>42</id>
<user>
<name>Ada Lovelace</name>
<roles>
<item>admin</item>
<item>dev</item>
</roles>
</user>
<active>true</active>
</root>Objects become nested elements, scalars become text, and arrays emit item children under a wrapper so the XML keeps a single root.
Attributes and mixed text
// JSON
{ "@id": "bk-101", "#text": "A classic novel", "title": "The Great Gatsby" }
// XML
<root id="bk-101">A classic novel<title>The Great Gatsby</title></root>A key starting with @ becomes an attribute of its parent; #text becomes text content. Both appear on one line so indentation cannot change the text.
Arrays with and without wrappers
// JSON
{ "tags": ["a", "b"] }
// Wrapped (default)
<root><tags><item>a</item><item>b</item></tags></root>
// Wrapper off
<root><tags>a</tags><tags>b</tags></root>With the wrapper off, the property element is repeated for each item so the key is never lost. A bare top-level array is refused because XML needs one root.
Examples
Nested object with an array
{"id":42,"user":{"name":"Ada","roles":["admin","dev"]}}<?xml version="1.0" encoding="UTF-8"?>
<root>
<id>42</id>
<user>
<name>Ada</name>
<roles>
<item>admin</item>
<item>dev</item>
</roles>
</user>
</root>Objects nest, scalars become text and array items are wrapped so the document keeps a single root.
Attributes plus text content
{"@id":"bk-101","#text":"A classic novel"}<root id="bk-101">A classic novel</root>The @ and # conventions let one element carry attributes and text without a nested wrapper element.
Unicode and sanitized names
{"café":"ü — “curly”","2nd":"x"}<root>
<café>ü — “curly”</café>
<field_1>x</field_1>
</root>Legal Unicode names and typography survive untouched; only names XML rejects are mapped to field_N and reported.
About this tool
The JSON to XML Converter turns JSON into well-formed XML with the mapping rules made explicit. Objects become nested elements, scalars become text, and arrays become repeated children. You choose the root element name, the array item tag, whether arrays get a wrapper, and how the document is indented — decisions that one-line converters usually make for you and often get wrong for SOAP endpoints, XSLT pipelines and XML-native config files.
Attribute and text handling follows two simple conventions. A key beginning with @ becomes an attribute of its parent (`{"@id":"7"}` becomes `<node id="7">`), and a `#text` key becomes that element's text content, so an attribute and a text value can coexist on the same element. Both conventions are optional; turn them off and the keys are emitted as ordinary child elements, with `@` replaced by a generated safe name.
The converter is deliberately strict about correctness. Names that XML rejects — leading digits, spaces, punctuation — become `field_N` names and appear in a report you can click to find the first occurrence; legal Unicode names such as `café` or `名前` are kept as written. Every value is escaped before serialization, and characters XML 1.0 forbids (control characters and lone surrogates) are rejected with a clear message instead of silently yielding a broken document. Large integers are emitted exactly as written, duplicate keys are all kept, and both conditions are reported.
Everything happens in your browser: no JSON is uploaded, and the result can be copied or downloaded as `converted.xml` with an optional XML declaration. Very large documents get a shortened preview so the page stays responsive; copy and download always contain the complete XML. Input is capped at 10 MB, and documents above 200,000 elements or 256 nesting levels are refused with guidance to split the file.
What this tool does not do
- No XSD generation or validation, XPath evaluation, or XML-to-JSON conversion; use the dedicated tools for those directions.
- Namespace prefixes other than the built-in xsi:nil declaration are not modeled; a colon in a key is treated as an invalid XML name.
- Large integers are copied verbatim into the XML, but downstream consumers that parse them as doubles can still lose precision.
- Mixed content is emitted inline on one line; values with significant whitespace should be checked against the receiving system's whitespace rules.
How to use this tool
Paste or upload JSON
Paste a JSON object, array, string or number, or load one of the example chips. Conversion updates as you type.
Choose the mapping rules
Set the root element and item tag, toggle array wrapping, @ attributes and # text, and pick the indent style.
Review the report
Sanitized names, collisions, duplicate keys and large integers are listed under the input. Click a chip to highlight its first occurrence in the XML.
Copy or download
Use Copy for the clipboard or Download .xml for a file with the XML declaration. Both use the full output, even when the preview is shortened.
Use cases
SOAP and legacy API payloads
Turn a JSON service response into the element-and-attribute shape an XML-only endpoint expects, with attribute and array rules you can see and adjust.
XML-native configuration
Generate config files for tools that only read XML, keeping source key order and choosing whether repeated values become wrapped or repeated elements.
Test fixtures from JSON data
Build well-formed XML fixtures from existing JSON test data while being told about duplicate keys, oversized integers and characters that would break XML 1.0.
Mapping rules at a glance
| JSON shape or key | XML it produces |
|---|---|
| Object property | Child element named after the key, in source order by default |
| Array with wrapper on | <tags><item>a</item><item>b</item></tags> |
| Array with wrapper off | <tags>a</tags><tags>b</tags> — the property element repeats |
| Key starting with @ | Attribute on the parent element (scalars only) |
| Key named #text | Text content of the parent element |
| null | Empty element; optional xsi:nil="true" adds the xmlns:xsi declaration |
| Invalid name, e.g. "2nd" | field_N with the original mapping listed in the report |
A bare top-level array cannot be emitted with wrapping off: XML documents need exactly one root element.
Common mistakes
Mistake:Assuming @ and # keys work the same in every converter.
Fix:Here @ applies only to scalar values — an object or array under @ becomes a child element and is flagged. #text becomes text on its parent, never a literal element named #text.
Mistake:Expecting numeric-looking keys to keep JavaScript's object order.
Fix:This tool reads the JSON source order directly, so keys like "10" and "2" stay where they were written. Keys that cannot be XML names are still mapped to field_N.
Mistake:Pasting XML-illegal control characters from spreadsheets or logs.
Fix:Beyond tab, line feed and carriage return, XML 1.0 forbids most C0 controls and lone surrogates. Remove or encode them; the tool reports the exact code point instead of producing invalid XML.
Mistake:Treating the shortened preview as the whole document.
Fix:The preview exists only to keep large documents responsive. Copy and download use the full XML; stats show element, attribute and depth totals for the complete result.
Frequently asked questions
How are JSON arrays converted to XML?
By default an array becomes a wrapper element named after its key with one <item> child per value: {"tags":["a","b"]} becomes <tags><item>a</item><item>b</item></tags>. Turn off Wrap arrays and the property element itself repeats instead: <tags>a</tags><tags>b</tags> — the key is never dropped. A top-level array with wrapping off is refused, because XML requires exactly one root element; wrap it in an object or leave wrapping on.
How do I make JSON properties become XML attributes?
Prefix the property name with @ and leave the @ attributes switch on. For example {"@id":"bk-101"} becomes <root id="bk-101">. Only scalar values can be attributes: an object or array under an @ key is emitted as a child element and reported. Attribute values are escaped, including quotes, ampersands, angle brackets and newlines, so the generated XML stays well-formed.
What happens to keys that aren't valid XML names?
They are mapped to field_N names — {"2nd":"x"} becomes <field_1>x</field_1> — and the original-to-generated mapping appears as a clickable chip under the input. If a generated name collides with another key, a -2 suffix is added and the collision is reported too. Legal Unicode names such as café or 名前 are kept exactly as written because they are valid XML names.
Can an element have both attributes and text?
Yes. Name the text value #text and keep the # text switch on: {"@id":"7","#text":"hello"} becomes <root id="7">hello</root>. Text and child elements on the same element are emitted on one line, so indentation never changes the text your XSLT or SOAP consumer receives. Several #text values are joined with spaces and noted in the report.
Is the XML validated?
Every conversion gets a defensive structural self-check that verifies matching tags, the XML declaration and CDATA sections; escaping is applied by the emitter rather than left to the browser. The tool also rejects characters XML 1.0 forbids — control characters, lone surrogates and noncharacters — before returning output. This is a well-formedness check, not schema validation: it does not verify your XML against an XSD or a particular API contract.
Will large numbers and duplicate keys be preserved?
Yes. The JSON reader keeps the original text of number literals, so 9007199254740993 stays exact in the XML instead of being rounded by JavaScript. Duplicate keys are all emitted as sibling elements rather than collapsing to the last value. Both cases appear in the report, because a downstream consumer using doubles may still round the number or treat repeated elements differently.
What happens with very large JSON files?
Input is limited to 10 MB, and documents above 200,000 elements or 256 nesting levels are refused with a suggestion to split them. For long results the preview shows only the first part so the page stays responsive, but Copy and Download always use the complete XML. Nothing is uploaded: conversion and rendering happen entirely in your browser tab.
References & standards
Related tools
Base32 Encoder / Decoder
Encode and decode Base32 (RFC 4648) with hex input mode and Crockford variant. Handles TOTP secrets. Runs in-browser.
Base58 Encoder / Decoder
Convert hex or text to Base58 and back, with Base58Check validation (version byte + checksum). IPFS CIDs too. In-browser.
Base64 Toolbox
Professional Base64 workspace for text, files and images with Base64URL, MIME, Data URI, strict validation, image preview and ready-to-use snippets.
BibTeX to JSON Converter
Parse .bib bibliographies into structured JSON with authors, months, macros and LaTeX cleanup, all in-browser.
C# to VB.NET Converter
Convert a subset of C# — classes, methods, variables, loops — into VB.NET
CSV Data Viewer
Paste CSV and inspect it as a sortable, searchable table with delimiter detection and inline export.