Skip to content

JSON to XML

Turn JSON into pretty XML with a configurable root element.

Live
Input

What this tool does

Turn JSON into pretty XML with a configurable root element and optional XML declaration. Each object key maps to an element, arrays repeat the parent tag, and special characters are escaped. Runs locally in your browser.

How to use it

Paste JSON (or load the example), pick a root element name, and read the XML on the right. Pretty-print and an optional <?xml …?> declaration are configurable.

Input: {"service":"devsmiths","public":true}

Output (XML):

<root>
  <service>devsmiths</service>
  <public>true</public>
</root>

Limits and edge cases

  • XML output is one-way (JSON → XML). XML → JSON is a separate problem (multiple valid mappings) and isn’t in scope for P1.
  • The mapping is element-only: there’s no attribute-vs-element heuristic. Every key becomes an element; arrays repeat the parent tag.
  • JSON keys that aren’t valid XML names (e.g. foo bar, names starting with a digit) will produce invalid XML — sanitize before converting.
  • For invalid JSON input, run the JSON Repair tool first.
  • For why JSON has largely replaced XML on the wire, see JSON vs YAML vs XML.

Frequently asked questions

Is my data sent to a server?
No. Every conversion runs in your browser — the page never uploads your JSON or its output.
Can I go YAML → JSON as well?
Yes — open /json/convert/yaml and toggle the 'YAML → JSON instead' option. CSV and XML are one-way for now (JSON → CSV / JSON → XML); the architecture supports reverse modes and they're on the roadmap.
How are nested objects handled in CSV?
By default nested keys are flattened with dots (e.g. user.address.city). Switch to bracket notation (user[address][city]) or 'stringify' to keep the nested value as a JSON-encoded cell. Arrays are JSON-stringified into a single cell — CSV's flat row-and-column model can't faithfully represent arbitrary nesting.
Does the XML output follow a schema?
No, it's a direct, conventional mapping: each object key becomes an element, arrays repeat the parent element, and primitive values become escaped text content. There's no attribute-vs-element heuristic — everything is an element. If you need attribute-style XML, a roadmap option is on the way.
Why does the CSV exporter complain about my input?
CSV needs an array (or single object). A bare string/number/boolean as the root has no row-and-column structure. Wrap it in an array of objects, or use the YAML / XML variant which handles arbitrary JSON.
Can the converter handle TSV, MessagePack, or TOML?
Not yet. The dispatch layer supports new targets — they're on the roadmap. Open an issue if you have a use-case.