XML to JSON Converter
Parse XML documents and convert to structured JSON, with attributes kept as @_-prefixed keys and well-formedness checks.
XML to JSON Converter tool
Example
Input: <user id="7"><name>Ada</name><age>36</age></user>
Result: A 2-space indented JSON object: { "user": { "name": "Ada", "age": 36, "@_id": "7" } }
Child elements become keys and numeric text such as 36 becomes a number. The id attribute is kept with an @_ prefix, here as the string "7".
XML to JSON Conversion Rules
| XML | JSON |
|---|---|
| <a>36</a> | {"a": 36} |
| <a>1.50</a> | {"a": 1.5} |
| <a>007</a> | {"a": "007"} |
| <a>true</a> | {"a": true} |
| <a/> | {"a": ""} |
| <a> hi </a> | {"a": "hi"} |
| <a id="7">x</a> | {"a": {"#text": "x", "@_id": "7"}} |
| <a><b>1</b><b>2</b></a> | {"a": {"b": [1, 2]}} |
| <a><![CDATA[<b>]]></a> | {"a": "<b>"} |
| <ns:a>x</ns:a> | {"ns:a": "x"} |
Output of this converter.
- Paste your XML document into the XML panel.
- Attributes are converted automatically to @_-prefixed keys and element text alongside them to #text keys.
- The parser validates your XML and reports any well-formedness errors with line and column numbers.
- Review the structured JSON output in the right panel with proper indentation.
- Click the copy button to copy the JSON for use in your modern application or API integration.
How XML Converts to JSON
This tool parses an XML document and writes it as formatted JSON. Child elements become keys, repeated elements become arrays, and attributes become keys that start with @_. So <user id="7"><name>Ada</name></user> becomes {"user": {"name": "Ada", "@_id": "7"}}.
The XML is checked first. If a tag is not closed or elements overlap, you get an error with the line and column instead of a half-converted result. Text that looks like a number or a boolean becomes one: <age>36</age> gives 36 and <ok>true</ok> gives true. Values with leading zeros (007) and hex text (0x1F) stay strings, so ZIP codes and IDs survive. Text is trimmed of surrounding spaces, and an empty element becomes an empty string. Attribute values are always kept as strings.
One pattern to watch: an element that appears once becomes a single value, while one that repeats becomes an array. So one item inside items gives "item": 1, but two give "item": [1, 2]. Code that reads the JSON should handle both shapes.
When an element has attributes or children and also text, the text goes into a #text key. CDATA content becomes plain text, comments are dropped, and namespace prefixes stay in the key, as in "ns:item".
The panels also work backwards, rebuilding XML from JSON that uses the same @_ and #text conventions. For control over the root name and indentation in that direction, use the JSON to XML Converter. To tidy the source XML first, try the XML Formatter.
Sources
Frequently Asked Questions
Related Tools
JSON to XML Converter
Convert JSON data to well-formed XML documents with customizable root element and formatting options.
Developer ToolsXML Formatter and Prettifier
Format, indent, and validate XML documents with customizable indentation and output options.
Developer ToolsJSON Formatter and Validator
Format, validate, beautify, and minify JSON data with a collapsible tree view and line-and-column error detection.
Developer ToolsJSON to YAML Converter
Convert JSON documents to YAML format with syntax validation, clean formatting, and instant preview.
Developer Tools