XML to JSON Converter

Free tool No sign-up
100% in-browser. Your XML / JSON never leaves your device — no server, no telemetry, no upload.
Direction
Options
Attribute prefix
How XML attributes appear in the JSON. <book id="x">"@id": "x"
Text-node key
Key for text content when a tag also has attributes.
Namespaces
<dc:title> "dc:title"
Force array (tag names)
Tags that should always be JSON arrays — even when only one appears. Fixes the #1 XML→JSON gotcha.
Type coercion
Output
Indent / minify the output.
Round-trip check
Input · XML
Output · JSON9 nodes · 0.4 KB
{
  "?xml": {
    "@version": 1,
    "@encoding": "UTF-8"
  },
  "library": {
    "book": [
      {
        "title": "The Pragmatic Programmer",
        "author": "David Thomas",
        "year": 1999,
        "@id": "b1",
        "@lang": "en"
      },
      {
        "title": "Refactoring",
        "author": "Martin Fowler",
        "year": 1999,
        "@id": "b2",
        "@lang": "en"
      }
    ]
  }
}

About this tool

Convert XML to JSON in your browser with the configuration knobs every other tool hides — pick the attribute prefix (@, _, $, @_, or none), control how namespaces are flattened, force tags to always become arrays, preserve CDATA, and verify the round-trip is lossless. Works equally well on SOAP responses, RSS feeds, Atom feeds, Maven POMs, sitemaps, and any XML you'd rather not paste into someone else's server. Bidirectional — flip the direction to convert JSON back to XML on the same screen.

?

Why use this XML to JSON converter?

🎛️
Real configuration knobs
Configurable attribute prefix (@, _, $, @_, none), text-node key (#text, _, $t, value), namespace handling (preserve / strip / drop). Most XML to JSON converters hardcode one set — this one lets you match whatever your API or library expects.
🔒
100% in-browser, no upload
Your XML and JSON never leave your device. Safe for SOAP responses, RSS feeds, customer data, internal API payloads, and anything you would not paste into a logged-in editor on someone else's server.
📐
Force-array fixes the #1 gotcha
When <item> appears once it becomes an object; when it appears twice it becomes an array — breaking your downstream code. Add tag names to "Force array" and they always parse as arrays, even with a single child.
↔️
Bidirectional XML ↔ JSON
Convert XML to JSON, then flip the direction and convert JSON back to XML — same options, same component. Turn on "Verify lossless" to round-trip your XML and see if anything was dropped along the way.

How to convert XML to JSON in 4 steps

01
Paste XML or drop a .xml file
Drop it into the left panel, paste from the clipboard, or pick a one-click example (RSS, SOAP, namespaces, CDATA). Conversion is live as you type.
02
Tune the attribute prefix
Pick @, _, $, @_, or "none" so XML attributes appear in JSON the way your downstream code expects.
03
Set namespace + force-array
Strip xmlns prefixes if you do not need them, and list tag names that should always be JSON arrays even when only one appears.
04
Copy or download
Hit Copy for the clipboard, Download for an output.json file, or flip the direction button to convert JSON back to XML on the same screen.

How it stacks up against other XML to JSON converters

FeatureThis toolMost tools
Bidirectional XML ↔ JSON✓ same screenseparate page or one-way only
Configurable attribute prefix✓ 5 optionshardcoded @_ or _
Namespace handling✓ preserve / strip / dropusually preserved only
Force-array list✓ comma-sepnever exposed
Type coercion (numbers, booleans)✓ togglesrarely exposed
CDATA preserve toggle✓ on by defaultoften dropped silently
Round-trip lossless check✓ one clicknot available
100% client-side privacy✓ verifiedoften server-side
=

Same XML, different JSON shapes

XML input
<?xml version="1.0" encoding="UTF-8"?>
<library>
  <book id="b1" lang="en">
    <title>The Pragmatic Programmer</title>
    <year>1999</year>
  </book>
</library>
Default JSON (one book)
{
  "?xml": { "@version": "1.0", "@encoding": "UTF-8" },
  "library": {
    "book": {
      "@id": "b1",
      "@lang": "en",
      "title": "The Pragmatic Programmer",
      "year": 1999
    }
  }
}
With force-array "book"
{
  "library": {
    "book": [
      {
        "@id": "b1",
        "@lang": "en",
        "title": "The Pragmatic Programmer",
        "year": 1999
      }
    ]
  }
}

Pro tips for XML to JSON conversion

01
Always-array tags fix arrays that disappear
If <book><item/></book> sometimes has one child and sometimes ten, your code breaks because the JSON shape changes. Add "item" to Force array and it stays an array of length 1, 2, or more — the contract is stable.
02
Strip xmlns prefixes for simpler JSON paths
SOAP and Atom XML are full of <soap:Body> and <atom:link>. Switching Namespaces to "Strip prefix" turns them into "Body" and "link" — cleaner JSON-path access in your code without losing the structure.
03
For SOAP responses, keep CDATA preserved
SOAP fault details often wrap HTML in CDATA. Without "Preserve CDATA" your HTML gets entity-encoded into <p>&lt;b&gt;…&lt;/b&gt;</p>. With it on, you get a clean #cdata key holding the raw HTML.
04
Use the round-trip check before relying on the JSON
Turn on "Verify lossless" to convert your XML to JSON and back. If the badge says "Lossy", something was dropped — usually comments, processing instructions, or element order. That tells you whether the JSON is a faithful representation or a one-way summary.
?

Frequently asked questions

01

How does XML to JSON with attributes work?

By default, XML to JSON with attributes prefixes each attribute with @ in the JSON output. <code>&lt;book id="b1" lang="en"&gt;</code> becomes <code>{"@id": "b1", "@lang": "en"}</code>. You can change the prefix to <code>_</code>, <code>$</code>, <code>@_</code>, or convert XML to JSON without the @ prefix at all (merge attributes directly into the object). The 'no prefix' option is useful when you want clean JSON keys for XML that has no element/attribute name collisions — set it to none and <code>&lt;book id="b1"&gt;Title&lt;/book&gt;</code> becomes <code>{"id": "b1", "#text": "Title"}</code> instead of <code>{"@id": "b1", "#text": "Title"}</code>. This is the standout knob most online XML to JSON converters do not expose — they hardcode <code>@_</code> or <code>-</code> with no way to change it.

02

How do I convert XML namespace to JSON?

The XML namespace to JSON conversion has three modes. <strong>Preserve</strong> (default) keeps prefixed keys like <code>"dc:title"</code> and includes <code>xmlns</code> declarations as attributes. <strong>Strip prefix</strong> turns <code>&lt;dc:title&gt;</code> into <code>"title"</code> — cleaner JSON paths, drops the xmlns declarations. <strong>Drop</strong> removes the prefixed key entirely (including all <code>&lt;atom:link&gt;</code>, <code>&lt;dc:creator&gt;</code>, etc.) for cases where you only want the un-namespaced content. Strip is the right pick for SOAP responses and Atom feeds where the namespace is consistent but not interesting to your parser. Preserve is right when you actually need to distinguish <code>dc:title</code> from <code>atom:title</code>.

03

How do I force array XML to JSON conversion for single elements?

This is the #1 XML to JSON array gotcha. When <code>&lt;book&gt;</code> appears once, parsers create an object: <code>{"book": {...}}</code>. When it appears twice, the same parser creates an array: <code>{"book": [{...}, {...}]}</code>. Your downstream code then has to check <code>Array.isArray()</code> on every access — and crashes the moment your data goes from one item to two. The fix is the <strong>Force array</strong> option. Add <code>book</code> (or any tag name) to the comma-separated list, and the force array XML to JSON behaviour kicks in — that tag always becomes a JSON array, length 1, 2, 10, whatever, so the shape stays stable. This is the single most important XML to JSON setting for production code, and almost no other online converter exposes it.

04

How does XML CDATA convert to JSON?

XML CDATA sections (<code>&lt;![CDATA[…]]&gt;</code>) are preserved by default into a <code>#cdata</code> key on the parent object — so the XML CDATA to JSON conversion is non-destructive. SOAP fault details often wrap HTML in CDATA, and RSS feeds use CDATA for post bodies — without preservation, the HTML inside gets entity-encoded (<code>&amp;lt;p&amp;gt;</code>) and becomes painful to render. With Preserve CDATA on, <code>&lt;body&gt;&lt;![CDATA[&lt;p&gt;Hello&lt;/p&gt;]]&gt;&lt;/body&gt;</code> becomes <code>{"body": {"#cdata": "&lt;p&gt;Hello&lt;/p&gt;"}}</code> — clean and easy to consume. Turn the toggle off if you want CDATA content merged into the text node instead.

05

Can I keep XML numbers as strings in the JSON output?

Yes — XML to JSON keep numbers as strings is one toggle away. Disable the 'Parse numbers' option. By default, <code>&lt;year&gt;1999&lt;/year&gt;</code> becomes <code>{"year": 1999}</code> (numeric). With parsing off it becomes <code>{"year": "1999"}</code> (string). This matters for ZIP codes, phone numbers, IDs with leading zeros, version strings like <code>1.2.0</code>, and anywhere your downstream code expects strings. 'Parse booleans' works the same way — controls whether <code>&lt;active&gt;true&lt;/active&gt;</code> becomes <code>true</code> or <code>"true"</code>.

06

Does this work for SOAP response to JSON, RSS to JSON, and Atom feed to JSON?

Yes — SOAP response to JSON, RSS to JSON, and Atom feed to JSON are the most common real-world XML to JSON conversions and this tool ships one-click examples for each. SOAP envelopes work cleanly with namespace handling set to 'Strip prefix' so <code>&lt;soap:Body&gt;</code> becomes <code>"Body"</code>. RSS to JSON works best with the <code>item</code> tag added to Force-array (so a single-item feed still produces an array). Atom feed to JSON wants <code>entry</code> in Force-array and <code>link</code> as well, plus 'Strip prefix' to clean up the <code>atom:</code> namespace. Maven POMs, Android manifests, sitemaps (<code>urlset</code> / <code>url</code>), and SVG files all parse cleanly with the defaults.

07

Is this a lossless XML to JSON round trip? Can I convert JSON back to XML?

Yes to both — this is a lossless XML to JSON round trip converter. Flip the direction button at the top to convert JSON back to XML — the same options panel applies (attribute prefix, text-node key, CDATA, indent). Turn on the <strong>Verify lossless</strong> toggle on the XML → JSON direction and the tool converts your XML to JSON, then back to XML, and compares the two. If the badge says 'Lossless', the round-trip is bit-exact (ignoring whitespace). If it says 'Lossy', something was dropped — usually XML comments, processing instructions other than <code>&lt;?xml&gt;</code>, or XML to JSON preserve order edge cases where strict element order matters. That tells you whether the JSON is a faithful representation or a one-way summary.

08

Are my XML and JSON sent to a server?

No. Conversion runs entirely in your browser — paste, drop, or load an example, all of it stays on your device. There is no network request involved, no telemetry on the conversion contents, and no analytics on what you paste. The site itself uses cookieless analytics (page views only) but the tool never reads or transmits your XML or JSON data. This matters for SOAP responses with customer PII, internal API payloads, and any XML you would not paste into a logged-in editor on someone else's server.

Search CodeFronts

Loading…