XML to JSON Converter

Paste XML and get clean, indented JSON, or paste JSON and get well-formed XML. Attributes become keys with a prefix of your choice, repeated tags become arrays, and an XML mistake is reported with its line and column. Use it to reshape a product feed, a sitemap, an RSS file or an old API response before you load it into a new app.

What you enter

What you get

How it works

  1. Choose XML to JSON or JSON to XML.
  2. Paste your data. The converter reads it with its own strict parser, so mismatched or unclosed tags are caught and located.
  3. Set the attribute prefix and the text key if the defaults (@ and #text) do not suit your code.
  4. Copy or download the result. Use the number option to turn values like 9.5 and true into real JSON numbers and booleans.

Why XML and JSON do not map one to one

XML was designed for documents. It has attributes, text that can sit between tags, comments and namespaces. JSON was designed for data and has objects, lists, numbers, booleans and null. Any converter has to make choices where the two disagree, and different tools make different choices, which is why the same file can give different JSON depending on where it was converted.

The convention used here is the common one. Attributes get a prefix so they cannot collide with child tags, text sits under a named key, and repeated tags form a list. If the receiving code already expects a specific shape, adjust the prefix and the text key to match instead of reshaping the data afterwards.

Fixing XML that will not parse

Strict XML parsers refuse input that browsers would forgive in HTML. Every tag must be closed, tags must close in the opposite order they opened, attribute values must be quoted, and there can be only one root element. The error message here gives the line and column where the parser gave up, which is usually at or just after the real mistake.

A bare ampersand is the most common culprit in hand-written feeds. A company name like Smith & Sons must be written Smith & Sons. The same goes for a less-than sign in text. If you control the source, wrap long free text in a CDATA section so these characters need no escaping.

Tips

Frequently asked questions

How are XML attributes shown in JSON?

Each attribute becomes a key made of your prefix and the attribute name. With the default prefix, <book id="7"> becomes {"book": {"@id": "7"}}. If the element also has text, the text goes under the text key, #text by default.

What happens to repeated tags?

Sibling tags with the same name become an array in the order they appear. Two <item> tags give "item": ["a", "b"]. A single <item> gives just a value, which is a limit of the format since XML does not say whether a tag may repeat.

Does it handle entities, CDATA and comments?

Yes. The five standard entities (&lt; &gt; &amp; &quot; &apos;) and numeric references like &#169; are decoded, CDATA sections are read as plain text, and comments, processing instructions and the DOCTYPE line are skipped. Custom entities defined in a DOCTYPE are not expanded and are reported as errors.

How does JSON become XML?

An object with one key supplies the root tag. Keys starting with the attribute prefix become attributes, arrays become repeated tags, null becomes an empty tag and text is escaped. If your JSON has several top-level keys or is an array, it is wrapped in a root tag.

Is my data uploaded?

No. Parsing and conversion happen in your browser and nothing is sent anywhere.

Related: JSON formatter, XML sitemap generator, JSON to CSV converter.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Free Tools

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap