{}JSON FYI
Convert

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.

EmptyInput: 0 BOutput: 0 B

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

Object with attributes and text
Input
{
  "user": {
    "@id": "u1",
    "@active": true,
    "#text": "Ada Lovelace"
  }
}
Output
<?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.

Arrays as repeated elements
Input
{
  "skills": ["math", "compilers", "kernels"]
}
Output
<?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.

Special character escaping
Input
{ "comment": "5 < 10 & valid" }
Output
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <comment>5 &lt; 10 &amp; valid</comment>
</root>

Use cases

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.

Convert JSON to XML

Read input.json, build XML elements from object keys (arrays repeat the parent element name), and write output.xml.

npm i fast-xml-parser && node to-xml.js
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 }));
Input
{
  "user": { "id": 1, "name": "Ada", "skills": ["math", "compilers"] }
}
Output
<?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.

Related tools & guides