JSON to XML Converter

Paste JSON on the left, get well-formed XML on the right. Keys starting with @_ become attributes. Runs entirely in your browser — no upload.

  1. Paste JSON into the left textarea.
  2. Click "Convert to XML". JSON keys become elements; @_keys become attributes.
  3. Copy or download the formatted XML.
  4. Wrap your data with a single root key — XML requires one top-level element.
What does it do?

Converts a JSON object to XML using the fast-xml-parser convention. Object properties become child elements; properties prefixed with `@_` become attributes on the parent; arrays become repeated sibling elements with the same tag name. Numbers, booleans, and strings are emitted as text content. The output is indented for readability.

Example

JSON input:

{
  "root": {
    "@_version": 1,
    "name": "Ada",
    "tags": ["math", "logic"]
  }
}

XML output:

<root version="1">
  <name>Ada</name>
  <tags>math</tags>
  <tags>logic</tags>
</root>

Common JSON-to-XML pitfalls

XML is stricter than JSON about structure. The patterns below cover most surprising output.

  • No single root. XML requires exactly one root element. JSON objects with multiple top-level keys produce multiple roots, which is invalid XML. Wrap your input in a single key: `{"root": {"a":1, "b":2}}`.
  • Top-level array. A JSON array `[{"a":1},{"a":2}]` has no root element name to use. Wrap it: `{"items": [{"a":1},{"a":2}]}`. Each array entry then becomes an `<items>` element.
  • Element names with spaces or symbols. XML element names cannot contain spaces, start with a digit, or contain `:`, `/`, `<`, etc. Sanitize JSON keys before converting — replace spaces with `_`, prefix digits with a letter.
  • Attributes vs. elements. A JSON key `id` becomes a child element `<id>1</id>`. To make it an attribute (`<user id="1">`), prefix the key with `@_`: `{"user":{"@_id":1}}`. The prefix is stripped on output.
  • Null values. JSON `null` becomes an empty element (`<x/>`). If you need it omitted entirely, strip null values from your JSON before converting.
  • Special characters in text. XML escapes `<`, `>`, `&`, `"`, and `\'` automatically. Your JSON string `"<b>hi</b>"` becomes the text `&lt;b&gt;hi&lt;/b&gt;`, not nested elements. Use intermediate JSON structure if you want actual nesting.
Frequently asked questions

How do I get an XML declaration `<?xml version="1.0"?>`?

Prepend it to the output yourself — the converter does not emit a declaration. For UTF-8 XML, the declaration is technically optional but commonly included: `<?xml version="1.0" encoding="UTF-8"?>` followed by your converted XML.

Are JSON arrays preserved as repeated elements?

Yes. `{"tags":["a","b"]}` becomes `<tags>a</tags><tags>b</tags>` — two siblings with the same tag, which is the standard XML representation of a repeated value.

Can I get JSON-style nested arrays in XML?

Not directly. XML has no native array concept; only repeated siblings. Nested arrays in JSON become a flatter XML structure where context determines grouping. Round-tripping XML → JSON → XML through this tool preserves the round-trippable subset.

How are dates handled?

JSON has no Date type — dates are typically already ISO 8601 strings. Those become element text content unchanged. If your XML downstream expects a particular date format, ensure the JSON uses that format.

Is my JSON uploaded?

No. Everything runs in your browser — your input is parsed and converted by JavaScript on this page and never sent to any server.

Will round-tripping JSON → XML → JSON preserve my data?

For typical structured data with the @_ attribute convention, yes — semantically. Some edge cases (mixed text + child elements, attribute order vs. element order) may normalize. If exact byte-equivalence matters, do not round-trip through XML.