JSON to XML & XML to JSON Converter
Convert JSON to XML or XML to JSON instantly in your browser.
Convert JSON to XML or XML to JSON instantly in your browser. Validate, format, copy, and download your data.
How to convert JSON to XML
- 1. Paste or upload your JSON. Switch to the JSON → XML tab, then paste JSON text, type it directly, or upload a
.jsonfile. - 2. Set a root element name (optional). Open Advanced options to rename the wrapping root element (default
root) and the element used for array items (defaultitem). - 3. Click Convert. The JSON is validated first — any syntax error or invalid element name is shown next to the input with its exact location.
- 4. Copy or download. Choose Pretty or Compact formatting, then copy the XML to your clipboard or download it as a file.
How to convert XML to JSON
- 1. Paste or upload your XML. Switch to the XML → JSON tab, then paste XML text or upload a
.xmlfile. - 2. Decide how values are typed (optional).By default, every leaf value stays a string — the safest choice for IDs and codes with leading zeros. Turn on "Convert true/false and plain numbers automatically" in Advanced options if you want ordinary booleans and numbers converted.
- 3. Click Convert. The XML is validated first — malformed XML, an undeclared namespace prefix, or unsupported mixed content is reported clearly.
- 4. Copy or download the resulting JSON in Pretty or Compact formatting.
JSON vs. XML: a practical comparison
| Trait | JSON | XML |
|---|---|---|
| Native types | string, number, boolean, null, object, array | Text only — types are a convention, not a format feature |
| Attributes | No equivalent — everything is a key | First-class, separate from child elements and text |
| Mixed content | Not applicable | Supported natively (text and elements interleaved) |
| Verbosity | Compact — no closing tags | Heavier — every element repeats its name on close |
| Common home | REST/GraphQL APIs, config files, NoSQL documents | SOAP APIs, legacy enterprise systems, document formats |
How attributes and arrays map between formats
An XML attribute becomes a JSON key prefixed with @, and text that sits alongside attributes or child elements becomes a key named #text. The reverse conversion understands this same convention, so JSON built this way converts cleanly back to XML attributes and text.
<product id="12"> <name>Desk</name> </product>
{ "product": { "@id": "12", "name": "Desk" } }
@id is an attribute, name is a child element — converting the JSON back reproduces the same XML.
Repeated sibling elements become an array. <tag>a</tag><tag>b</tag> becomes "tag": ["a", "b"], and converting that array back produces the same two repeated elements.
Real uses for converting between JSON and XML
- API payloads — adapting a response from a legacy SOAP or XML-based API into JSON for a modern frontend, or the reverse for a partner integration that only accepts XML.
- Configuration files — converting an XML configuration (Maven, Android, Spring) to JSON for a build script, or generating XML config output from a JSON source of truth.
- Data exports — turning an XML export from an older system into JSON for analysis or import into a document database.
- Legacy integrations — bridging a newer JSON-based service with an older enterprise system that still speaks XML.
Mapping limitations to keep in mind
Converting between JSON and XML is not universally lossless— the two formats don't model data the same way, so a few cases are worth understanding before you rely on a round trip:
- Null, empty string, and empty array all collapse — XML has no native null, so
null,"", and{}all become the same empty element (<a/>), and an empty array produces no element at all. Converting that empty element back to JSON always producesnull— the original distinction can't be recovered. - Mixed content is reported, not rearranged — an element like
<p>Hello <b>world</b>!</p>has text on both sides of a child element. That ordering can't be represented faithfully in this tool's JSON shape, so it's returned as a clear unsupported-content error instead of being silently reordered or dropped. - CDATA boundaries aren't preserved — a
<![CDATA[...]]>section is treated as plain text; the fact that it was originally wrapped in CDATA is not retained. - Comments and processing instructions are omitted — neither has a JSON equivalent, so both are dropped when converting XML to JSON.
- Namespaces are preserved, not resolved — a declared namespace prefix and its
xmlnsattribute are kept as-is. An element using an undeclared prefix is rejected with a clear error rather than silently stripped. - Large integers stay exact— a 19-digit database ID or a value with leading zeros is kept as text by default (and even with automatic type conversion turned on) specifically so it's never silently rounded or reformatted.
More developer tools
Working with an API response that mixes JSON and XML? The API Response & JSON Inspector explores a JSON payload in a tree and generates TypeScript, Zod, and more. If a field inside your data is Base64-encoded, the Base64 Encoder & Decoder handles that separately. Need sample records to test either format against? The Mock Data Generator builds CSV, JSON, and SQL fixtures from a schema. And for more free tools like this one, browse the full Developer Resources Directory.
Common questions
Is my JSON or XML data uploaded anywhere?+
No. Every conversion runs locally in your browser using standard JavaScript — nothing you paste, upload, or convert is sent to a server or included in analytics.
How are JSON arrays represented in XML?+
An array value becomes a repeated element with the same name as its key — for example {"tags":["a","b"]} becomes <tags>a</tags><tags>b</tags>. A top-level array is wrapped in the root element, with each item rendered using the configurable item element name (item by default).
How are XML attributes represented in JSON?+
Each attribute becomes a key prefixed with @ on the enclosing object, and text that appears alongside attributes or child elements becomes a #text key — for example <product id="12"><name>Desk</name></product> becomes {"product":{"@id":"12","name":"Desk"}}.
What happens with invalid JSON or XML?+
The tool validates before converting and shows a clear error next to the input — including the exact JSON path (like $.items[2].name) or a line/column position when the parser reliably provides one. Nothing is guessed or fabricated.
Is there a file size limit?+
Yes — input is limited to 2 MB and 64 levels of nesting, both checked before conversion starts, so a very large or deeply nested file fails fast with a clear message instead of freezing the tab.
Can I convert XML back to the exact same JSON, or JSON back to the exact same XML?+
Often, but not always — it isn't universally lossless. XML has no native null, so null, an empty string, and an empty array can all collapse to the same empty element. True mixed content (text interleaved with elements on more than one side, like <p>Hello <b>world</b>!</p>) can't be mapped to JSON without losing or reordering the text, so it's reported as unsupported rather than silently rearranged. Comments and processing instructions are also not carried over to JSON.
More free resources

Have a project in mind? Let's build it.
Tell us about your goals and we'll get back to you within one business day with next steps.
Book a free call