XML and JSON Converter
Convert XML to JSON and JSON to XML in both directions, with control over attributes and indentation. All in your browser, nothing uploaded.
What this tool does
It converts XML to JSON and JSON to XML in both directions, with a swap button that moves the result into the input. Everything happens in your browser.
It is the conversion you need when you have to consume a SOAP service from a modern application, when you inherit an XML feed and your code speaks JSON, or when you want to inspect a document’s structure with the tools you are used to.
The two things XML has and JSON does not
This is the important part of this tool. The conversion is not symmetric, because the two formats do not express the same things, and knowing that avoids surprises.
Attributes
In XML, <price currency="MXN">100</price> has an attribute and some content. JSON has no such distinction — only keys. If currency became an ordinary key, it would be indistinguishable from a child element called currency, and converting back would put it in the wrong place.
The fix is to mark them with a prefix, @_ by default:
{ "price": { "@_currency": "MXN", "#text": 100 } }
That way the trip back to XML knows what was an attribute and what was content. You can change the prefix or drop attributes entirely in the settings.
One or many
This is the one that really bites. In XML, an element that appears once and one that appears three times are written the same way: by repeating the tag. In JSON you have to choose between a plain value and an array.
With two <line> elements you get an array. With one, you get an object. The same schema produces differently shaped JSON depending on how many children the particular document carries.
If you are consuming the result in code, this is the trap to account for: a client that always expects an array breaks the day an order arrives with a single line. The usual defence is to normalise in your own code, wrapping loose values in an array.
What is lost in a round trip
The structure and the data survive the full trip. What does not:
- Comments. JSON has no comments to keep them in.
- CDATA sections. The content survives, but it stops being marked as CDATA.
- Ordering between different elements, which in JSON depends on object key order.
- The
<?xml ... ?>declaration and prefixed namespaces, which get flattened.
If what you need is to preserve the document exactly as written, do not go through JSON: use the XML formatter, which respects all of it.
About the engine
The conversion uses fast-xml-parser (MIT licence) in both directions. Syntax errors, in both XML and JSON, are shown with their line and column.
Frequently asked questions
Why do some keys have @_ in front?
Because JSON cannot tell an attribute from a child element: in XML, id="7" and an id element are different things, and in JSON both would be a key called id. The prefix marks which ones came from attributes so they can be put back in place when converting the other way. You can change it or turn attributes off in the settings.
Does an element that appears only once become an array?
No, and that is the delicate part of the conversion. An element that appears twice becomes an array; one that appears once becomes a plain value. That means two documents with the same structure can produce differently shaped JSON depending on how many children they have. If you are consuming the result in code, account for it.
Does a round trip return the exact original?
The structure and data yes, but not necessarily the formatting: comments and CDATA sections are lost, because JSON has nowhere to keep them. If what you need is to preserve the document as-is, use the XML formatter instead of going through JSON.
Is my file uploaded to a server?
No. The conversion happens entirely in your browser. You can confirm it in the network tab of your developer tools: converting fires no request.
Reviews & ratings
No reviews yet. Be the first to leave one!
Related tools
Others from the catalogue that pair well with this one.