JSON to XML — Convert JSON Objects to XML Online

🔒 Runs in your browser — nothing is sent to a server

JSON to XML converts any JSON object or array into a well-formed XML document in one click. Paste an API response, a config file, a JavaScript object dump or a hand-written JSON blob, and this JSON to XML converter walks the tree with the `fast-xml-parser` builder, treats keys prefixed with `@` as XML attributes, the special `#text` key as mixed text content, repeated array values as repeated elements, and emits pretty-printed XML with a configurable indent and the optional `<?xml ?>` declaration. Pick a custom root element name when the JSON has multiple top-level keys. Everything runs 100% inside your browser; your JSON never leaves your device, nothing is uploaded, logged or sent to any server.

Two-pane view: input and output side by side
Copied!

When to use a JSON to XML converter online

You reach for a JSON to XML converter any time JSON-shaped data needs to flow into an XML-native consumer: building a SOAP request body for a legacy enterprise service, generating a SAML assertion payload, transforming a JavaScript object into an SVG snippet, producing an Atom or RSS feed item, or constructing an Office Open XML part for a `.docx` template. Browser-local conversion matters when the JSON contains customer data, internal admin payloads, signing material or any sensitive content you would rather not paste into a remote SaaS converter — the data stays on your machine, nothing is logged or cached.

How JSON to XML conversion works under the hood

JSON to XML conversion is a parse-then-build pipeline. The browser-native `JSON.parse` validates the input and produces an in-memory JavaScript value; any syntax error surfaces immediately with a clear message. The converter checks whether the parsed value already has exactly one top-level key (a natural root) or whether it needs the configurable Root element name to wrap multiple keys, an array, or a primitive. The fast-xml-parser builder then walks the tree: keys prefixed with `@` become XML attributes on the parent tag, the special `#text` key becomes inline text, arrays expand into repeated elements with the parent key as the tag name, primitive leaves become text nodes. Pretty-printing applies the chosen indent (2 spaces, 4 spaces, or tab); the XML declaration is prepended when the option is on; empty elements collapse to `<a/>` when self-closing is enabled. The whole pipeline runs inside the browser engine in milliseconds.

Examples

Input
{
  "book": {
    "@id": "1",
    "@available": "true",
    "title": "Atlas",
    "author": "A. Reyes",
    "year": 2024
  }
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<book id="1" available="true">
  <title>Atlas</title>
  <author>A. Reyes</author>
  <year>2024</year>
</book>
JSON to XML — typical object with attributes mapped via @-prefix
Input
{
  "catalog": {
    "book": [
      { "@id": "1", "title": "Atlas" },
      { "@id": "2", "title": "Vesper" },
      { "@id": "3", "title": "Beacon" }
    ]
  }
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="1">
    <title>Atlas</title>
  </book>
  <book id="2">
    <title>Vesper</title>
  </book>
  <book id="3">
    <title>Beacon</title>
  </book>
</catalog>
Convert JSON to XML — array of objects becomes repeated elements
Input
{
  "tool": {
    "name": "json to xml",
    "role": "transform json to xml with attribute mapping",
    "client": "free-converter.online"
  }
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<tool>
  <name>json to xml</name>
  <role>transform json to xml with attribute mapping</role>
  <client>free-converter.online</client>
</tool>
JSON xml converter — payload that names the tool itself
Input
{
  "title": "Atlas",
  "author": "A. Reyes",
  "year": 2024
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <title>Atlas</title>
  <author>A. Reyes</author>
  <year>2024</year>
</root>
Serialize JSON as XML — multi-key root wrapped in custom element

FAQ

How do I convert a JSON object to XML?

Paste the JSON into the input above, pick a root element name if your JSON has multiple top-level keys, and click Convert to XML. The converter validates the JSON with `JSON.parse`, walks the resulting tree with the `fast-xml-parser` builder, treats `@`-prefixed keys as attributes and the special `#text` key as mixed text, then emits pretty-printed XML with a configurable indent.

How does the JSON to XML converter map attributes vs. child elements?

Keys prefixed with `@` become XML attributes — `{"book": {"@id": "1", "title": "Atlas"}}` produces `<book id="1"><title>Atlas</title></book>`. Other keys become child elements. The special key `#text` holds mixed text content for elements that have both attributes and inline text. This is the same convention the matching XML to JSON tool uses, so the pair round-trips losslessly.

What happens to JSON arrays?

A JSON array under a key becomes repeated XML elements with that key as the tag name. `{"items": [1, 2, 3]}` serialises to `<items>1</items><items>2</items><items>3</items>`. This mirrors how XML expresses repetition without an explicit array type. Empty arrays produce no elements; arrays of objects produce repeated complex elements with the same shape.

Why does my JSON need a root element?

XML requires exactly one root element while JSON allows multiple top-level keys (`{"a":1,"b":2}` is valid JSON, but `<a>1</a><b>2</b>` is not valid XML). When the input JSON has more than one top-level key, the converter wraps it in the configurable Root element name (default `root`). When the JSON already has exactly one top-level key, that key becomes the root and no wrapping is needed.

How do I produce self-closing tags for empty elements?

Turn on "Self-closing tags for empty elements". An empty JSON value (`""`, `null`, empty object) then produces `<a/>` instead of `<a></a>`. Self-closing is the canonical XML form for empty elements; some downstream parsers prefer the explicit open-close pair, in which case turn the option off.

Can I produce XML without the `<?xml ?>` declaration?

Yes — turn off "Include XML declaration". The output becomes a bare XML fragment, which is what you usually want when the result will be embedded inside another XML document, signed as part of a SAML assertion, or sent over a transport that already declares its own encoding.

How is JSON to XML different from XML to JSON?

JSON to XML and XML to JSON are inverse operations under the same convention (`@` for attributes, `#text` for mixed text). JSON to XML serialises a key-value tree into a tag-oriented document for SOAP, SVG or any XML-native consumer. XML to JSON parses XML into JSON for JavaScript consumption. Round-trips cleanly when both tools share the same convention settings.

Is it safe to paste sensitive JSON into this online JSON to XML converter?

Yes — the JSON to XML converter runs entirely in your browser via the `fast-xml-parser` library bundled into the page. Your JSON and the XML output stay on your machine; nothing is uploaded, logged or cached. Safe for SAML payloads, SOAP envelopes, customer exports, internal admin reports and any data you would not want a remote SaaS converter to retain.

Glossary

JSON (JavaScript Object Notation)

JSON is a lightweight, text-based data format that represents structured data as nested objects, arrays, strings, numbers, booleans and null. Defined by RFC 8259 and ECMA-404, JSON is the de-facto wire format for HTTP APIs, configuration files, package manifests and IPC. JSON to XML conversion lets JSON-native systems feed into XML-native consumers — SOAP services, signed SAML payloads, SVG, RSS and Atom feeds.

XML (Extensible Markup Language)

XML is a text-based, tag-oriented format defined by the W3C XML 1.0 spec. It powers SOAP and WS-* web services, RSS and Atom feeds, Office Open XML, Android layouts, SVG and countless legacy enterprise systems. Converting JSON to XML lets modern JSON-first pipelines hand off data to systems that still speak XML.

Attribute mapping convention

XML has both attributes and child elements; JSON has only key-value pairs. To round-trip XML through JSON without losing information, converters adopt a convention — this tool uses `@` as the attribute prefix and `#text` for mixed text content. Other conventions (Badgerfish, Parker, JsonML) exist but the `@` / `#text` pair is the most readable and the most widely supported in modern tooling.

Root element

XML requires exactly one root element wrapping the document. When the input JSON has more than one top-level key, the converter wraps the whole tree in a configurable root element (default `root`). When the JSON already has one top-level key, that key becomes the root naturally — `{"book": {...}}` serialises to `<book>...</book>` with no extra wrapping.

XML declaration

The XML declaration is the optional first line of an XML document — `<?xml version="1.0" encoding="UTF-8"?>` — that pins the XML version and the character encoding. Most consumers accept XML with or without the declaration, but it is good practice to include it when the output is the entire document, and to omit it when the output is a fragment embedded inside another document.

Self-closing tag

A self-closing tag — `<a/>` — is the canonical XML form for an element with no content. The longer form `<a></a>` parses identically. Some downstream consumers prefer one over the other for diff or templating reasons; this converter exposes a toggle so you can produce whichever your target system expects.

Related tools