XML

XML to JSON Converter

Convert XML data to JSON format instantly — free, private, and right in your browser.

Your XML is parsed and converted locally in your browser. No data is uploaded to any server.

1
Paste XML here...

0 characters

JSON result will appear here...

0 characters

How to use

  1. Paste your XML into the left panel (or click Load sample to try it out).
  2. Choose your options: pretty print, preserve attributes, keep the XML declaration.
  3. Click Convert XML to JSON.
  4. Copy the JSON or download it as a .json file.

How XML maps to JSON

XML and JSON model data differently: XML mixes structure into tags and attributes, while JSON uses plain key-value pairs. This converter walks the XML tree and applies a set of predictable mapping rules so the output is easy to consume in JavaScript, Python, or any JSON-native toolchain.

Supported XML features:

  • XML elements and nested elements (objects inside objects)
  • Attributes — kept as @name keys when "Preserve attributes" is on
  • Repeated sibling elements — automatically become JSON arrays
  • Text nodes and CDATA sections — CDATA content is treated as plain text
  • XML declaration — optionally kept as an @declaration key
  • Numeric and boolean leaf values are typed (<age>30</age>30)

Looking for the reverse conversion? Use the JSON to XML Converter →

Examples

Simple element

<person><name>John</name><age>30</age></person> becomes {"person": {"name": "John", "age": 30}} — numbers are inferred automatically.

Repeated tags become arrays

<tags><tag>a</tag><tag>b</tag></tags> becomes {"tags": {"tag": ["a", "b"]}}, matching how most APIs expect list data.

Attributes preserved

<user id="42"><name>Jane</name></user> becomes {"user": {"@id": "42", "name": "Jane"}} when attribute preservation is enabled.

Frequently Asked Questions

What is XML to JSON conversion?+
It is the process of translating XML markup into an equivalent JSON structure: elements become object keys, nested elements become nested objects, repeated elements become arrays, and text content becomes string, number, or boolean values.
How do I convert XML to JSON?+
Paste your XML into the input panel, click Convert XML to JSON, then copy or download the result. Formatting and attribute handling can be adjusted with the options above the editor.
Is this XML to JSON converter free?+
Yes — completely free, with no registration, no usage limits, and no watermarks.
Is my XML uploaded to a server?+
No. Conversion runs entirely in your browser using the built-in DOMParser API. You can verify this by converting a document while offline after the page has loaded.
How are XML attributes converted?+
With "Preserve attributes" enabled, each attribute becomes a key prefixed with @ (for example id="42" becomes "@id": "42"). With it disabled, attributes are dropped and only element content is kept.
What happens with CDATA sections?+
CDATA content is treated as regular text — it appears in the JSON output as a plain string value without any escaping artifacts.
My XML is invalid — what now?+
The converter reports the parser error with line and column where available. Fix the syntax with the XML Formatter or check it with the XML Validator.

Related Tools

Looking for something else? Browse all tools