Skip to content

Formatters & Code

JSON ⇄ XML Converter

Convert JSON to XML or XML to JSON — both directions.

Runs in your browser
JSON · source
lines: 0chars: 0size: 0 B
JSON
XML · target
lines: 0chars: 0size: 0 B
XML

Understanding JSON ⇄ XML

Two shapes for the same data.

Convert cleanly, but know what each format won't carry across.

The fundamental shape difference.

JSON is a tree of values — strings, numbers, booleans, arrays, objects — keyed by names. XML is a tree of elements — each one a tag, optionally with attributes, containing text or other elements. JSON has no concept of attributes; XML has no concept of arrays. Round-tripping between them therefore needs a convention.

{ "user": { "name": "Ada" } } ⇄ <user><name>Ada</name></user>

Arrays in XML.

XML expresses repetition by repeating elements: <role>admin</role><role>editor</role>. JSON uses an explicit array. When converting JSON arrays to XML this tool emits one element per item; when converting XML to JSON it gathers same-named siblings into an array. A single<role> with no siblings becomes a string, not an array — keep that in mind for schemas that always expect a list.

Attributes vs. children.

XML elements can carry attributes — <book id="42"> — that have no JSON equivalent. The common convention (and the one this tool uses) is to fold attributes into the JSON object under prefixed keys: { "@id": "42", "#text": "…" }. Converting that JSON back to XML restores the attribute. If your XML uses attributes heavily and you need a strict round-trip, plan for those @-prefixed keys.

Comments, processing instructions, namespaces.

JSON has no syntax for any of these — comments, XML declarations (<?xml version="1.0"?>), and namespace prefixes vanish on the JSON side. If you need to keep a <?xml-stylesheet?> processing instruction or a set of xmlns declarations across the round-trip, treat XML as the source of truth and store JSON as a read-only projection.

When to pick which.

JSON wins for web APIs, JavaScript-heavy stacks, and anywhere minimal-overhead transmission matters — every byte you send on the wire counts. XML wins where you need attributes, schema validation (XSD), namespaces (industry-specific dialects like SOAP, OOXML, SVG), or document-style content mixing markup and text. RSS and Atom feeds, configuration files for older tooling, and EDI document formats stay XML because the alternatives are worse, not because XML is enjoyable.

Frequently asked questions

Quick answers.

How are JSON arrays converted to XML?

Each array item becomes a repeated element with the parent key. So {"items":[1,2]} → <items>1</items><items>2</items>.

What about JSON keys that aren't valid XML names?

Keys with spaces or special characters are sanitised to valid XML names. Numeric keys are prefixed with an underscore.

Is my JSON sent anywhere?

No — conversion runs entirely in your browser. Your data never leaves your device.

Can I convert XML back to JSON?

Yes — see our XML to JSON converter for the reverse direction.

Is the converter free?

Yes — free, no signup, runs in your browser.

People also search for

Use with

What people reach for next.

Related tools

More in this room.

See all in Formatters & Code