Skip to main content
Convert2JSON Tools

XML to JSON Converter

Read an XML document as JSON, with explicit control over the two things every XML-to-JSON mapping must decide: attributes and arrays.

Your data stays on your device

Input — XML

characters
0
lines
0
size
0 B

Output — JSON

characters
0
lines
0
size
0 B

Options

Comma separated. Keeps the shape stable when an element sometimes appears once.

About this tool

Every XML-to-JSON converter has to answer the same questions. Where do attributes go, since JSON has no notion of them? What happens when an element appears once in one document and three times in another? Silent guessing is what makes converted output unpredictable.

Here the answers are options you set. Attributes are collected under a configurable prefix, mixed text content goes to a named key, and you can force specific elements to always be arrays so your consuming code does not have to handle both shapes.

How to use this tool

  1. Paste XML or upload a .xml file.
  2. Set the attribute prefix (@ by default) and the text node key (#text by default).
  3. Enable "Always use arrays for repeated elements" if your consumer needs a stable shape.
  4. Press Convert and copy or download the JSON.

Key features

  • Attributes preserved under a configurable prefix
  • Configurable key for mixed text content
  • Automatic array detection for repeated sibling elements
  • Option to force arrays so single and repeated elements share one shape
  • Optional trimming of insignificant whitespace between elements
  • Namespace prefixes retained in key names, or stripped on request

Example

Attributes and repeated elements

InputXML

<order id="A-19">
  <item sku="X1">Cable</item>
  <item sku="X2">Adapter</item>
</order>

OutputJSON

{
  "order": {
    "@id": "A-19",
    "item": [
      { "@sku": "X1", "#text": "Cable" },
      { "@sku": "X2", "#text": "Adapter" }
    ]
  }
}

Good to know

  • Comments, processing instructions and DOCTYPE declarations are dropped; they have no JSON equivalent.
  • XML values are untyped text. "42" arrives as a string unless you enable numeric coercion, which can misfire on values like leading-zero postcodes.
  • CDATA sections are converted to plain text content, so the CDATA wrapper itself is not preserved.

Frequently asked questions

Why is a single element not an array?

Because XML cannot distinguish "one item" from "a list containing one item". If your schema says a field is a list, enable the force-array option and name the element so it is always emitted as an array.

Where did my attributes go?

Into keys prefixed with @ by default, alongside the element children. Change or clear the prefix in the options panel if you prefer another convention.

Should I enable numeric coercion?

Only when you know the data. It is convenient for counts and prices, but it will turn "007" into 7 and can lose leading zeros in identifiers.

Are XML namespaces supported?

Prefixed names such as ns:item are preserved as-is in the key by default. You can strip prefixes if they add noise to your output.

Your data stays on your device

Your data is processed locally in your browser and is not uploaded to our server. This page keeps working after you go offline, because there is nothing to send.

Share this toolXLinkedInHacker News