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
- Direction
- XML or JSON
- Attribute prefix
- Text key
- Convert numbers and true/false
- Add the XML declaration line
- Indent
What you get
- Status
How it works
- Choose XML to JSON or JSON to XML.
- Paste your data. The converter reads it with its own strict parser, so mismatched or unclosed tags are caught and located.
- Set the attribute prefix and the text key if the defaults (@ and #text) do not suit your code.
- 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
- A tag that appears once becomes a single value and the same tag appearing twice becomes an array. If your code expects a list, wrap the result or convert single values to arrays after parsing.
- XML has no number type, so everything is text unless you tick the number option. Leave it off for IDs, phone numbers and postcodes, where a leading zero matters.
- Mixed content, such as text between child tags, cannot keep its exact position in JSON. The pieces of text are joined and stored under the text key.
- When going from JSON to XML, every key must be a valid XML name: letters, digits, hyphens, underscores, dots and colons, not starting with a digit. A key like first name is rejected.
- Namespaces are kept as part of the tag name, so a tag like dc:title becomes the key dc:title.
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 (< > & " ') and numeric references like © 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 a 7-day free trial or see all free tools. On We.Inc you get a 7-day free trial, not a free plan: card needed, $0 today, cancel before it ends and you pay nothing. AI building is on paid plans from $20 a month.
More in Free Tools
- YAML to JSON Converter
- A2A Agent Card Generator and Validator
- Landing Page A/B Test Calculator
- Free Accessibility Statement Generator & Template
- Accessible Color Palette Generator
- Ad Budget Calculator
- Ad Copy Generator
- Add to Calendar Link Generator
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App