JSON to XML converter
Convert JSON into well-formed XML with configurable root element, indentation, and attribute support. Useful for legacy SOAP APIs, RSS feeds, config files, and XPath-driven systems.
Ready when you are.
Paste JSON on the left, or click Sample to try a quick example. The XML output appears here as you type — entirely in your browser.
The conventions used
JSON and XML overlap but aren't isomorphic — XML has elements, attributes, and text content, while JSON has objects, arrays, and primitives. To bridge the gap, JSON FYI follows two widely-used conventions:
- Attributes via the @ prefix. A key like
"@id"becomes an attribute on the parent element instead of a child element. - Text content via the #text key. When an element has both attributes and text, use
"#text"to specify the text content.
Arrays are emitted as repeated elements with the parent's name, which is the standard XML idiom (<tag>1</tag><tag>2</tag> rather than <tags>[1, 2]</tags>). Null becomes xsi:nil="true" on the element.
All special characters are escaped per the XML 1.0 specification, so output is safe to drop into any XML parser, XSLT pipeline, or XPath query.
Examples
{
"user": {
"@id": "u1",
"@active": true,
"#text": "Ada Lovelace"
}
}<?xml version="1.0" encoding="UTF-8"?>
<root>
<user id="u1" active="true">
Ada Lovelace
</user>
</root>@-prefixed keys map to attributes; #text becomes the element's text content.
{
"skills": ["math", "compilers", "kernels"]
}<?xml version="1.0" encoding="UTF-8"?> <root> <skills>math</skills> <skills>compilers</skills> <skills>kernels</skills> </root>
Each array item becomes a repeated element with the parent's name — the standard XML idiom.
{ "comment": "5 < 10 & valid" }<?xml version="1.0" encoding="UTF-8"?> <root> <comment>5 < 10 & valid</comment> </root>
Use cases
- Calling legacy SOAP APIs
Many enterprise systems still expect XML payloads. Convert your modern JSON in one click.
- Generating RSS or sitemap entries
Build XML feeds from JSON sources without templating libraries.
- Migrating to a new format
Inspect what your JSON looks like as XML before committing to a schema migration.
- Driving XPath / XSLT pipelines
Get XML you can query with XPath when JSONPath isn't an option.
- Config files for older tools
Some build systems and Java apps read XML — convert your JSON config first.
Frequently asked questions
How is each JSON value mapped to XML?+
Objects become elements, arrays become repeated elements with the same name, primitives become text content, and null becomes an element with xsi:nil="true".
How do I produce XML attributes?+
Prefix the JSON key with @ — keys like "@id" become attributes on the parent element. Use the "#text" key when an element needs both attributes and text content.
What about invalid XML element names?+
JSON allows any string as a key, but XML element names must start with a letter or underscore. Invalid characters are replaced with underscores so the output is always parseable.
Does it produce a valid XML declaration?+
Yes — the converter emits <?xml version="1.0" encoding="UTF-8"?> by default. Disable with the XML declaration toggle if you're embedding the result inside another document.
Are special characters escaped?+
Yes. <, >, and & are escaped in text. ", <, &, and newlines are escaped inside attribute values. The output is safe to embed in any XML-aware tool.
Is the conversion lossless?+
Almost. JSON object key order is preserved, types are flattened to text (XML has no native number/boolean), and the @ / #text conventions let you round-trip if you build the JSON to match.
Convert JSON to XML in code
JavaScript, Python, Go, and Ruby snippets — copy and paste into your project.
Read input.json, build XML elements from object keys (arrays repeat the parent element name), and write output.xml.
import { readFileSync, writeFileSync } from "node:fs";
import { XMLBuilder } from "fast-xml-parser";
const data = JSON.parse(readFileSync("input.json", "utf8"));
const builder = new XMLBuilder({ format: true, indentBy: " ", suppressEmptyNode: true });
writeFileSync("output.xml", '<?xml version="1.0" encoding="UTF-8"?>\n' + builder.build({ root: data }));{
"user": { "id": 1, "name": "Ada", "skills": ["math", "compilers"] }
}<?xml version="1.0" encoding="UTF-8"?>
<root>
<user>
<id>1</id>
<name>Ada</name>
<skills>math</skills>
<skills>compilers</skills>
</user>
</root>Other JSON tools on JSON FYI
Every flow you need — formatter, validator, viewer, pretty print, repair, and the full workbench.
Pretty-print with custom indent and sort keys.
Strict RFC 8259 syntax check with line + column.
Browse JSON as an interactive collapsible tree.
Compare two JSON files structurally with paths.
Convert arrays into spreadsheet-ready CSV.
Idiomatic YAML 1.2 for Kubernetes & Compose.
Beautify JSON with JS- or Python-style indent.
Free in-browser formatter — nothing uploaded.
Pinpoint errors with a catalog of common fixes.
Validate data against a JSON Schema — powered by Ajv.
All tools in one editor: validate, format, view, query.