DevPik Logo

XML to JSON Converter

Bidirectional XML ↔ JSON converter with attribute prefixing (@ or _), auto-detection of repeated elements as arrays, CDATA handling, and customizable root element — great for SOAP and RSS.

Why Use XML to JSON Converter?

Many legacy systems still speak XML — SOAP endpoints, RSS feeds, bank integrations, government APIs, Maven poms — while the apps consuming them are JavaScript or Python apps that prefer JSON. A reliable bidirectional converter bridges the gap without requiring you to write XML parsing code you'll delete in a year. It also preserves features XML has that JSON doesn't: attributes (mapped with `@`-prefixed keys), CDATA sections, and namespaces. Useful for RSS feed parsing, SOAP response debugging, and exporting Android `strings.xml` to a web-friendly format.

How to Use XML to JSON Converter

  1. Paste your XML into the left input panel. The tool converts it to JSON in real-time as you type.
  2. Adjust options: choose attribute prefix (@, _, or none), select indentation (compact, 2, or 4 spaces).
  3. Click the Swap button to switch to JSON → XML mode and convert JSON back to XML.
  4. Upload XML or JSON files directly using the Upload button, or drag and drop.
  5. Copy the output to your clipboard or download it as a .json or .xml file.

Worked Examples

RSS feed item → JSON

Input
<item><title>Post</title><pubDate>2026-04-15</pubDate></item>
Output
{"item":{"title":"Post","pubDate":"2026-04-15"}}

Map directly into a blog feed renderer or database.

Attributes captured with @ prefix

Input
<book id="1" lang="en"><title>1984</title></book>
Output
{"book":{"@id":"1","@lang":"en","title":"1984"}}

The @ prefix disambiguates attributes from nested elements.

Repeated elements auto-become arrays

Input
<items><item>A</item><item>B</item><item>C</item></items>
Output
{"items":{"item":["A","B","C"]}}

No manual array wrapping required — repeated tags are merged automatically.

About XML to JSON Converter

The XML to JSON Converter is a free online tool that converts between XML and JSON formats instantly. XML (eXtensible Markup Language) and JSON (JavaScript Object Notation) are the two most widely used data interchange formats. XML is common in enterprise systems, SOAP APIs, RSS feeds, SVG files, and Android configurations, while JSON dominates REST APIs, web applications, and modern config files. This bidirectional converter handles XML attributes (mapped with configurable prefixes like @ or _), nested elements, repeated elements (auto-detected as arrays), CDATA sections, self-closing tags, and mixed content. The JSON to XML mode generates well-formed XML with optional XML declarations and customizable root element names. Everything runs 100% client-side in your browser — your data never leaves your device.

Troubleshooting & Common Issues

Single-item XML becomes an object, not an array

If your producer sometimes emits one element and sometimes many with the same tag, the converter can't tell — one item becomes an object, multiple become an array. Always treat such fields as arrays in consuming code, or enable "force array" mode listing the element names that should always be arrays.

Namespaces (xmlns:ns=...) clutter the output

XML namespaces appear as `@xmlns:*` attributes. For display purposes you can filter them out, but if you convert back to XML you'll lose the namespace binding. If namespaces don't matter to your consumer, strip them before the JSON-to-XML round trip.

Mixed content (text + nested tags) loses text

XML allows text interspersed with elements (`<p>Hello <b>world</b></p>`) which has no direct JSON mapping. The converter stores the text content under a `#text` key. If you're losing text, check for mixed content and use a dedicated HTML-to-JSON approach instead.

Reverse conversion doesn't restore the exact original XML

XML is order-sensitive for child elements, but JSON objects are not. Order of keys within an object may shift, though the tool tries to preserve insertion order. For byte-perfect round-tripping, use an XML-specific library — JSON is inherently a lossy intermediate form for XML.

Frequently Asked Questions

How do I convert XML to JSON?

Paste your XML into the left input panel and the tool instantly converts it to JSON in the right panel. XML attributes are prefixed with @ by default (customizable), repeated child elements become arrays, and text content is preserved. Copy or download the result when ready.

How does the converter handle XML attributes?

XML attributes are converted to JSON properties with a configurable prefix. By default, an attribute like category="fiction" becomes "@category": "fiction" in JSON. You can change the prefix to underscore (_) or remove it entirely.

Can I convert JSON to XML?

Yes! Click the Swap button to switch to JSON → XML mode. Paste JSON in the left panel and get well-formed XML output. Properties prefixed with @ or _ are converted back to XML attributes. You can customize the root element name and toggle the XML declaration.

How are repeated XML elements handled?

Repeated child elements with the same tag name are automatically detected and converted to JSON arrays. For example, multiple <item> elements inside a parent become a JSON array. This auto-detection works at every nesting level.

Does the converter handle CDATA sections?

Yes. CDATA sections in XML are extracted and their content is included as text in the JSON output. The CDATA wrapper is removed since JSON doesn't have an equivalent concept.

What is the difference between XML and JSON?

XML uses tags with opening/closing elements and supports attributes, namespaces, and comments. JSON uses key-value pairs with a simpler syntax. JSON is more compact and easier to parse in JavaScript, while XML offers more metadata capabilities through attributes and schemas like XSD.

Is my data safe when converting?

Yes. This XML to JSON converter runs 100% client-side in your browser. No data is ever transmitted to any server. You can safely convert sensitive XML or JSON data.

Related Tools

Was this tool helpful?