XML to JSON

Runs in browser JSON & Data

Parse XML in the browser and produce a predictable JSON structure: attributes are prefixed, repeated children become arrays, and text content is preserved.

Privacy: This tool runs entirely in your browser. Your input never leaves your device.
Loading tool…

What changes when data is converted between JSON, CSV, YAML and XML?

The four formats model data differently: JSON and YAML carry nesting and types, CSV is a flat table of strings, and XML distinguishes elements from attributes. A converter therefore has to make choices — how to flatten nested objects into columns, how to type "42" and "true", where attributes go — and the right choice depends on what the receiving system expects.

Read the guide: What is JSON?

How to use XML to JSON

  1. Paste the XML document.
  2. Decide whether to keep attributes, parse numbers/booleans and which elements must always be arrays.
  3. Copy or download the JSON.
One <product> becomes an object and two become an array; listing product under Always-array elements gives an array every time.

Occurs once

One <product> inside <catalog>

"product": { "name": "Keyboard", "@_id": "p-1" }

Always-array elements:
Empty
product in the JSON:
Object

Repeated

Two sibling <product> elements, as in the example

"product": [ { "name": "Keyboard", "@_id": "p-1" }, { "name": "Mouse", "@_id": "p-2" } ]

Always-array elements:
Empty
product in the JSON:
Array of 2

Once, forced to an array

The same single <product>, with product listed as always-array

"product": [ { "name": "Keyboard", "@_id": "p-1" } ]

Always-array elements:
product
product in the JSON:
Array of 1

Each code box is the entry under "catalog" in the tool’s own output for that XML, with the default options; the attribute id becomes "@_id".

XML to JSON features

  • Well-formedness check with line and column for malformed XML
  • Attributes preserved with the @_ prefix (or dropped on request)
  • Repeated children become arrays; force arrays for specific element names
  • Optional conversion of numeric and boolean text values
  • CDATA content and entities decoded
  • Summary of root element, element count and depth

XML to JSON example

Catalog with attributes and repeated elements

Input:

<catalog><product id="p-1"><name>Keyboard</name></product><product id="p-2"><name>Mouse</name></product></catalog>

Output:

{
  "catalog": {
    "product": [
      { "name": "Keyboard", "@_id": "p-1" },
      { "name": "Mouse", "@_id": "p-2" }
    ]
  }
}

Frequently asked questions about XML to JSON

How are attributes represented?

Attributes become keys prefixed with @_ (e.g. "@_id"). If an element has both attributes and text, the text is stored under "#text". You can also drop attributes entirely.

Why is one element an object but another an array?

Repeated sibling elements are collected into an array; an element that occurs once stays an object. List element names under "Always-array elements" to force a consistent array shape.

Are numbers and booleans converted?

By default text such as 42, 3.5 and true is converted to JSON numbers and booleans. Disable "Parse numbers & booleans" to keep every value as a string (useful for zip codes and IDs with leading zeros).

What about CDATA, comments and namespaces?

CDATA content is included as text, comments and processing instructions are dropped, and namespaced names such as soap:Body are kept verbatim as keys.

References