JSON to XML

Turn a JSON document into XML, and decide how keys become elements and attributes.

Runs on your deviceDataWorkingNo account needed

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

  1. 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.
  2. 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.
  3. 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.
  4. 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?
No. The parsing and the conversion both run in this browser tab, so the document is not transmitted, logged or stored, and the tool keeps working with the network disconnected.
How are arrays converted?
An array inside an object repeats that object's key, so "tags": ["x", "y"] gives two tags elements next to each other with no container around them. That is what XML consumers usually expect. An array that is the whole document works differently: whether it sits at the top level or behind a single top-level key used as the root, its items take the Array item element name, which defaults to item.
What about an array inside an array?
The inner grouping is lost. XML cannot write a list of lists without a wrapper element, and this converter does not invent one, so [[1, 2], [3]] flattens to three sibling elements in a row with nothing marking where the first list ended. Wrap those inner arrays in named objects before converting if the grouping matters.
How do I get an attribute rather than a child element?
Prefix the key with @ and give it a scalar value: "@id": "7" becomes id="7" on the enclosing element. An @-prefixed key holding an object or an array cannot be an attribute, so it is written as a child element instead, with the @ replaced by an underscore because @ is not legal in an element name.
Are numbers and booleans preserved?
Not as types. XML elements hold text, so 42, "42" and true all serialise the same way, and null becomes an empty element. If types matter downstream, the receiving schema or parser has to restore them.
What happens to a key like "2020 total"?
It is not a legal XML element name, so it is rewritten as _2020_total and the original is preserved in a name attribute. Two cases lose that marker: an object that already carries its own @name, because emitting both would produce a duplicate attribute and unparseable XML, and an array, whose repeated elements are written without it.
Can I convert the result back to JSON?
Yes, with XML to JSON, but not as a lossless round trip. Types are already gone, an element that appeared once will not come back as a one-item array unless you force it, and any key that had to be renamed comes back under its rewritten name.
Does it validate against a schema?
No. Element names are made legal, text and attribute values are escaped and control codes are stripped, which covers the mistakes people actually hit — but nothing here checks the document against a DTD or an XSD, and it will not tell you that a required element is missing. A handful of codepoints XML also rejects, such as U+FFFE and an unpaired surrogate, pass through unchanged and will stop the output parsing.

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.