What does an XML to JSON converter do?
It reads an XML document and produces the equivalent JSON, so that data defined in one format can be consumed by code written for the other. That is more or less a daily need: SOAP responses, RSS and Atom feeds, configuration files, sitemaps and the output of older enterprise systems are all XML, while the code that wants to read them almost always expects objects.
The conversion is not a translation, because the two formats do not describe the same things. XML has attributes, mixed content in which text and elements interleave, and comments and processing instructions; JSON has none of those. Each one has to be given a convention, and the conventions differ between implementations, which is why two XML to JSON tools produce different output from the same input.
This tool makes those decisions visible. Attributes can be prefixed so they cannot collide with a child element of the same name, mixed text can be kept under a text key, and a repeated element becomes an array. A single occurrence is the awkward case — an object by default, or a one-item array for a stable shape — and that is offered as a choice rather than decided for you.
How to convert XML to JSON
- Paste an XML document into the box, or press Load an example for a small catalogue with attributes and repeated elements.
- Watch for a parse error. Anything not well-formed is reported with the parser's own message, and nothing is converted.
- Decide how attributes should appear. The default prefixes them with @ so an id attribute and an id child element stay distinct.
- Decide the array behaviour. Leave it off for the tidiest JSON, or turn it on so every child is an array and the shape does not change when a second item arrives.
- Choose an indentation, or Minified for the smallest output.
- Copy the JSON, or download it as a file named after the root element.
XML to JSON Converter limits and rules
| Item | Limit |
|---|---|
| Input | A well-formed XML document or fragment |
| Attributes | Under a prefix of your choice, @ by default |
| Text | Element text becomes a string when there are no children or attributes |
| Mixed content | Text kept under a text key alongside the child elements |
| Repeated elements | Always an array, whatever the count |
| Single elements | An object by default, or a one-item array if you ask for it |
| Namespaces | Kept as part of the element name, prefix and all |
| Dropped | Comments, processing instructions and the XML declaration itself |
When to use it
- Turning a SOAP or REST response into objects your code can read directly.
- Converting an RSS or Atom feed into JSON for a front-end that does not parse XML.
- Reading a configuration file or a sitemap into a script you are writing.
- Inspecting an unfamiliar XML document to see its structure before writing a parser for it.
- Producing fixture data in JSON from an XML sample, for tests.
Is it private?
The XML is parsed by the browser's own parser inside this page. Nothing is uploaded, stored or logged, which matters if the document contains a customer record, a licence file or anything else you would rather not paste into a web service.
Frequently asked questions
Because otherwise the conversion is lossy in a way that bites later. XML lets an element have both an attribute called id and a child element called id, and the two are different pieces of data; without a distinguishing convention they collapse into one key in the object and whichever was written last wins. The @ prefix is what the widely used xml2js convention in the JavaScript world does, and the tool lets you change the prefix if your consumer expects something else, including an empty string if you accept that risk.
It is kept, under a #text key, but the order is lost. An XML element may contain text, then a child element, then more text, and the sequence is significant to anyone reading it; JSON has no way to express that interleaving, so the text is gathered into a single string on one key and the elements sit beside it. Documents that are really narrative markup convert badly for this reason, and documents that are rows and records convert well. Neither the tool nor any other can preserve information JSON cannot hold.
It depends on who reads the result. The default — object for one, array for many — is what most conventions do and gives the shortest JSON, but it changes the shape of the data as soon as a second item appears, so downstream code that does items.map(...) works today and throws tomorrow. Switching on always-array makes the shape constant at the cost of a little noise, and that is usually the safer choice for anything that is genuinely a list. It is a design decision about your consumer, not a property of XML.
It checks that it is well-formed, which means the syntax is correct: tags are balanced, quotes are closed, text does not contain a stray ampersand. That is a different thing from valid, which in XML means conforming to a schema or a DTD that says which elements and attributes are allowed where. The tool will not validate against a schema, and a document that passes here can still be wrong in the sense a schema describes.
The namespace prefix is kept as part of the element name, so atom:entry arrives as the key atom:entry rather than entry. That preserves the distinction between two prefixes binding to different namespaces, and it avoids inventing a resolution rule. What it does not do is expand the prefix to the namespace URI or record the xmlns attributes separately, so if your consumer needs the full namespace information, that is something this conversion does not carry and you would need a format that does.
Not with this tool. Going back is genuinely harder, because JSON carries no record of which keys were elements, which were attributes and what order the children came in, and a converter has to guess or be told. Where round-tripping matters, keep the original XML as the source of truth and treat the JSON as a projection of it. That is also the sane arrangement if the document is edited: convert on the way out, never on the way back in.
Related tools
Written and maintained by Md. Nur Hossain Repon.