Skip to content

XML to JSON converter

Paste XML. JSON is written beside it, or the parser error is shown.

Values stay strings. XML has no number or boolean type, so convert them in your code where you need to.

Ctrl+Enter or ⌘+Enter runs this tool immediately.

JSON output
XML
JSON

Waiting for input.

Parsing stays in this browser. Input is not uploaded or saved.

How to use this tool

  1. Paste an XML document, such as a pom.xml, an RSS feed, or a SOAP response, or load the sample.
  2. Read the JSON. Attributes are keys starting with @, and an element with attributes and text keeps the text under #text.
  3. Copy or download the result.

Supported formats and limitations

  • An element that appears once is an object or string. The same element repeated becomes an array, so a list with one item is not an array.
  • Comments and processing instructions are dropped.
  • An element with both text and child elements keeps its text under #text, but where the text sat between the children is lost.
  • Namespace prefixes are kept as part of the name, such as soap:Body.
  • DOCTYPE entity declarations are rejected rather than expanded.

Examples

Attributes and text

<dependency scope="test">vitest</dependency> becomes {"#text": "vitest", "@scope": "test"}.

<dependency scope="test">vitest</dependency>

Repeated elements

Two <tag> elements become "tag": ["a", "b"].

<post><tag>a</tag><tag>b</tag></post>

Common errors and solutions

Expected closing tag 'b' (opened in line 2, col 3) instead of closing tag 'c'.
A closing tag does not match the element it closes. Go to the line and column shown and fix the name or nesting.
XML has one root element.
Wrap the elements in a single parent element, such as <items>...</items>.
Entity declarations (<!ENTITY>) are not expanded.
Remove the entity declarations from the DOCTYPE and replace references such as &name; with their text.

FAQ

Why is a list with one item not an array?
XML does not say whether an element can repeat. One <tag> looks the same as a single value, so it becomes a value. Wrap it in an array in your code if it can repeat.
Why are numbers strings?
XML text has no types, so 2.1 and true are text. Keeping them as strings avoids turning a version or a zip code into a number.
Is the XML uploaded?
No. It is converted in your browser.

Related tools

  • JSON to XML converter

    Convert JSON to indented XML in the browser. Keys starting with @ become attributes, arrays become repeated elements, and special characters are escaped.

  • JSON formatter

    Validate JSON, then pretty-print it with 2 or 4 spaces or minify it. Invalid JSON produces an error and leaves the output empty.

  • JSON to YAML converter

    Convert valid JSON into YAML with 2-space or 4-space indentation. Nested objects, arrays, and multiline strings are preserved, and invalid JSON is reported instead of repaired.