Data Tools
XML to JSON Converter (and JSON to XML)
Convert XML to JSON in your browser with attributes as @keys, repeated elements as arrays and CDATA kept intact, or turn JSON back into indented XML.
How to use XML to JSON Converter (and JSON to XML)
Paste XML and the JSON appears as you type; paste JSON starting with { or [ and it is converted back to XML. Choose how attributes are written, the indent and the type options, then press Copy result.
- Paste XML or JSONPaste a full XML document or fragment. Input starting with { or [ is read as JSON and converted to XML.
- Set attribute and type optionsChoose @ or _ attribute prefixes or ignore attributes, and tick type conversion, arrays or namespace stripping.
- Copy the converted outputPick 2 spaces, 4 spaces, Tab or Minified (one line) as the indent, then press Copy result.
Conversion rules with an example
In the sample, the library element has a name attribute and two book children. The result starts {"library": {"@name": "City Library", "book": [...]}}: attributes become keys with an @ prefix, the two book elements are merged into an array, and elements that hold only text, such as title, become plain strings. When an element has text as well as attributes or children, the text goes under #text. Empty elements become empty strings, comments and processing instructions are dropped, and CDATA content such as Open 9:00-17:00 & weekends is kept as written. Values stay strings unless you tick Convert numbers and true/false to JSON types, which turns "1965" into 1965.
Options, namespaces and JSON back to XML
Always put child elements in arrays wraps even single children in arrays, so code can loop over them without checking. Strip namespace prefixes turns soap:Body into Body and drops xmlns declarations. Even with type conversion on, values such as 007 and integers too large to store exactly stay strings. In the JSON to XML direction the same rules run backwards: keys starting with the attribute prefix become attributes, #text becomes element text, arrays become repeated elements and null becomes an empty element. Keys that are not valid XML names have the invalid characters replaced, so bad key becomes bad_key, and several top-level keys are wrapped in a root element.
Accuracy and data handling
Keep the original data and spot-check fields, types and delimiters before using an important conversion. The calculation runs in your current browser; the tool code does not send the input to a processing API.
FAQ
Are numbers converted to JSON numbers?
Not by default: all text is kept as strings so values such as 007 keep their leading zeros. Tick Convert numbers and true/false to JSON types to turn plain numbers and true or false into JSON numbers and booleans.
How are XML attributes shown in JSON?
Each attribute becomes a key with an @ prefix, so id="1" becomes "@id": "1". You can switch to an _ prefix or ignore attributes altogether.
Do repeated elements become arrays?
Yes. Elements with the same name under one parent are combined into an array. A single child stays a plain value unless you tick Always put child elements in arrays.
Is my XML uploaded?
No. The XML is parsed by your browser's built-in XML parser, so the document is converted on your own device and is not sent to a server.
More Data Tools
Related toolsTurn CSV into a GitHub Markdown table, or a Markdown table back into CSV.
Convert tab-separated spreadsheet data to CSV, or CSV back to TSV.
Switch CSV delimiters between comma, semicolon, tab and pipe, with decimal options.
Sort JSON keys alphabetically at every level, with optional array sorting.
Deep merge JSON documents, apply a Merge Patch and see which values changed.
Compare two JSON documents and list every added, removed or changed value.