JSON to XML
Turn a JSON document into XML, and decide how keys become elements and attributes.
What this tool does
JSON to XML reads your input with the browser's JSON parser and writes an XML document from the value that comes back. The mapping between the two is a convention, not a standard: JSON and XML disagree about what a document even is, so every XML converter has to invent rules for attributes, repeated values and text. This one's rules are in the settings panel rather than buried in the code, so you can see them and change them.
The defaults follow the pattern most hand-written mappings use. A key beginning with @ becomes an attribute, so "@id": "7" is written as id="7" instead of a child element. A key named #text supplies an element's text content, which is how you attach words to an element that also carries attributes. An array nested inside an object repeats that object's key once per item, so "tags": ["x", "y"] becomes two adjacent tags elements rather than a wrapper full of children. An array that is the whole document is the exception: its items are named by the Array item element setting instead. Both markers are settings — if your data already uses @ or #text for something else, choose different ones.
What XML will not carry back is type. Numbers, booleans and strings all arrive as element text, and null becomes an empty self-closing element, so a return trip through XML to JSON gives you strings unless you ask that tool to cast them. Keys that are not legal XML element names are rewritten — spaces and punctuation become underscores, a leading digit gains one — and the original key is kept in a name attribute, unless the value is an array or the object already supplies its own name, in which cases the original spelling is lost. Duplicate keys collapse to the last one when the JSON is parsed, and control codes below space, which XML 1.0 forbids, are stripped from text and attribute values.
The work happens in this browser tab and the JSON is not uploaded, which matters because the documents people convert here are usually API payloads and exports carrying identifiers, addresses and tokens. There is no file picker either: you paste the text, so a document big enough to strain one tab is the practical ceiling. Nor is there a validation step — text and attributes are escaped so the result parses, but nothing checks it against a DTD or an XSD, and no namespaces are generated for you. A namespace has to arrive in your JSON as an attribute, such as "@xmlns".
How to use it
- Start with the JSON. Put it in the input box, or press Load sample for a document that exercises attributes, nesting and arrays. Invalid input is reported with the parser's own message.
- Decide what the root element is. Leave "Use a single top-level key as the root element" on and { "order": … } becomes an order element. Switch it off, or start from an array, and the Root element name is used instead.
- Set the attribute and text markers. The attribute prefix defaults to @ and the text-content key to #text. Array item element names the items of an array that becomes the document itself — one at the top level, or the array behind a single top-level key.
- Choose the indentation and the declaration. Two spaces, four spaces or a tab. None puts the whole document on one line, below the XML declaration if you keep that switched on.
Processing & privacy
Runs on your device. Your file is processed directly in this browser.
Common use cases
Feeding a JSON payload to a system that only speaks XML
Older billing, logistics and government endpoints often accept nothing else. This produces the document without writing a serialiser for a one-off job.
Drafting a small feed or config by hand
Writing the structure as JSON is faster and less error-prone than typing angle brackets, and the conversion handles the escaping of & and < for you.
Checking how a gateway will reshape your data
Convert a sample request and read the element names it produces before you agree a mapping with the other side, rather than after the first rejected message.
Producing a fixture for an XML parser test
One representative payload converted with the same settings each time gives you a stable document to assert against.
Questions
Does the JSON leave my browser?
How are arrays converted?
What about an array inside an array?
How do I get an attribute rather than a child element?
Are numbers and booleans preserved?
What happens to a key like "2020 total"?
Can I convert the result back to JSON?
Does it validate against a schema?
Related tools
- JSON to CSV — Flatten a JSON array into a CSV table.
- CSV to JSON — Turn a CSV file into structured JSON.
- CSV Viewer — Open and browse a large CSV without a spreadsheet app.
- CSV to Excel — Convert CSV files into an XLSX workbook.
- Excel to CSV — Export spreadsheet sheets to CSV.
- CSV Merge — Combine multiple CSV files with matching columns.