JSON to XML & XML to JSON Converter
Free online JSON to XML and XML to JSON converter. Custom root tag, indented well-formed output and repeated array siblings for SOAP, RSS and legacy APIs.
JSON to XML conversion maps each object key to an element tag, primitive values to tag text, and repeated array items to sibling elements under one root node. Paste JSON on the left, set the root tag name, and the right pane returns indented, well-formed XML.
📊 Real-Time Structural Payload Evaluation
Programmatic Execution Modules
Native runtime recipes for automated pipelines • Zero external cloud dependencies
npx xml-js --compact input.json > output.xmlexport function jsonToXmlNode(key: string, val: unknown): string {
if (val === null || val === undefined) return `<${key}/>`;
if (Array.isArray(val)) {
return val.map((item) => jsonToXmlNode(key, item)).join('');
}
if (typeof val === 'object') {
const inner = Object.entries(val)
.map(([k, v]) => jsonToXmlNode(k, v))
.join('');
return `<${key}>${inner}</${key}>`;
}
const escaped = String(val)
.replace(/&/g, '&')
.replace(/</g, '<')
.replace(/>/g, '>');
return `<${key}>${escaped}</${key}>`;
}Single Root Element W3C Constraint
W3C Well-Formedness ViolationW3C XML strictly forbids multiple root-level nodes. While JSON allows multiple top-level keys or root arrays, XML requires an enclosing wrapper tag (<root>).
CDATA Boundaries & XML Entity Escaping
Entity Injection DefenseUnescaped ampersands (&), brackets (< >), and quotes in string values break XML parsers. Payloads with raw HTML or special symbols must be CDATA-wrapped (<![CDATA[...]]>).
📚 Task-Specific Reference Guides & Specifications
2 Technical GuidesFrequently Asked Questions: JSON to XML
Why does converting JSON root arrays or multiple sibling keys require a synthetic XML root node?
Under the W3C XML 1.0 (Fifth Edition) Specification (Section 2.1), every well-formed XML document must contain exactly one root document entity enclosing all subordinate elements. Because JSON allows top-level arrays (e.g. `[{"id": 1}, {"id": 2}]`) or multiple root-level keys without a singular parent container, attempting to serialize them directly would produce multi-root markup that causes fatal syntax errors in standard DOM and SAX parsers. The converter wraps all root contents within a configurable wrapper element (such as `<root>`, `<response>`, or `<data>`) to guarantee strict well-formedness compliance.
How are primitive arrays and heterogeneous sequences serialized into valid child XML tags?
In JSON, array members are anonymous, indexed values without associated dictionary keys. To serialize primitive lists (e.g. `["admin", "dev"]` or numeric matrices `[10, 20]`), the engine wraps each individual array item in a repeated sibling `<item>` node within the parent element (yielding `<roles><item>admin</item><item>dev</item></roles>`). For arrays of nested objects, each child object generates repeated element tags matching the parent key or a singularized item tag, ensuring downstream XML schema validators (XSD) can validate repeatable sequences without encountering tagless text nodes.
How does the converter handle XML reserved characters and CDATA boundary conditions in string values?
All primitive string values undergo character reference encoding for the five predefined XML entities: ampersand (`&` → `&`), less-than (`<` → `<`), greater-than (`>` → `>`), quotation mark (`"` → `"`), and apostrophe (`'` → `'`). When string values contain raw HTML fragments, unescaped scripts, or binary data strings, encoding them as standard text nodes prevents parser abortion. For complex payload blocks, CDATA sections (`<![CDATA[...]]>`) can be utilized to pass unparsed character streams without triggering XML parser entity evaluation.
How are XML attributes discriminated from nested child elements during bidirectional JSON ↔ XML conversion?
Standard JSON has no native syntax distinction between attributes and child nodes. During bidirectional translation, this tool adheres to standard XML-JSON mapping conventions: elements map directly to object keys, while attribute-aware parsers recognize prefix markers (such as `@_attr` or `_attributes`). In XML → JSON mode, element text content is isolated into value properties, sibling tags with identical names collapse into typed arrays, and XML namespace declarations (`xmlns:xsi`, `xmlns:soap`) are safely extracted as string properties without corrupting node hierarchies.
Why is reverse XML-to-JSON parsing subject to numeric and boolean type coercion ambiguities?
Unlike JSON—where data types (numbers, booleans, strings, null) are syntactically explicit through quotes and literal keywords—XML stores all element values as untyped character data (PCDATA). When reversing XML back to JSON, the parser applies contextual lexical inference: values strictly matching integer or floating-point patterns are converted to JSON numbers, while `"true"` and `"false"` become boolean literals. However, leading-zero strings (like postal codes `"00123"` or telephone extensions) are preserved as strings to prevent loss of significant digits.
🔍 Developer Query Intent Index
How to use the JSON to XML
Step-by-step workflow — executed 100% locally in your browser memory.
- 1
Paste JSON
Put your document into the left-hand input pane, or switch the toggle to XML → JSON to convert the other way.
- 2
Set the root element
XML requires exactly one root element while JSON does not, so choose a wrapper name such as root, data, or response.
- 3
Read the XML
The right-hand pane shows indented, well-formed XML with reserved characters escaped as entities.
- 4
Copy into your request
Copy the document into a SOAP body, a feed template, or a legacy integration payload.
⚡ Technical Specifications & Engineering Compliance Matrix
| Specification Standard | W3C XML 1.0 (Fifth Edition) / Namespaces in XML 1.0 |
|---|---|
| Architecture: | schema-synthesizer |
| Time Complexity | O(N) recursive node emission |
| Memory Footprint | O(N) XML element builder buffer |
| Data Privacy & Egress | Zero remote transmission (100% in-browser memory) |
| Last reviewed | by the JSON2X Core Team. |
Related Developer Tools
Architecture: schema-synthesizer •Spec: W3C XML 1.0 (Fifth Edition) / Namespaces in XML 1.0 •Last reviewed by the JSON2X Core Team.