XML to JSON Converter
Convert an XML document into JSON that is easy to work with in code. Repeated elements become arrays, attributes are kept under @ keys, and you decide whether numbers and booleans are detected. The conversion happens in your browser.
- Runs in your browser
- No sign-up
- Free to use
How to use XML to JSON
- Paste XML into the left pane or open an XML, RSS or SVG file.
- Choose whether to keep attributes, detect numbers and booleans and keep the root element.
- Select Convert to JSON.
- Copy the JSON or download it as a .json file.
XML to JSON features
Arrays where they belong
Elements that occur more than once under the same parent become a JSON array.
Attributes preserved
Attributes are stored under keys beginning with @, and mixed text under #text.
Optional type detection
Turns “42” into 42 and “true” into true only when you ask for it, and never for values like 007.
CDATA and entities
CDATA sections and character entities are decoded into plain text.
Well-formedness check
Malformed XML is rejected with the line and column of the problem.
Local processing
Parsing uses your browser's XML engine; the document is not sent anywhere.
When to use XML to JSON
- Reading an RSS or Atom feed in JavaScript.
- Working with the response of a SOAP or legacy XML API.
- Migrating configuration or export files to a JSON-based system.
- Inspecting a large XML file in a JSON viewer.
XML to JSON FAQ
How are XML attributes represented in JSON?
Each attribute becomes a key that starts with @. <book id="b1"> gives {"@id": "b1"}. If the element has attributes and text, the text is stored under #text. Untick Keep attributes to drop them.
When does an element become an array?
When two or more elements with the same name appear under one parent. A parent with a single child of that name gets a plain object or value, because XML itself does not say whether a list was intended. If your code expects an array, check for both cases or normalise afterwards.
Why are numbers kept as strings by default?
XML has no number type; everything is text. Guessing can corrupt data, for example postal codes or identifiers with leading zeros. With the option enabled, only values that are unambiguous numbers or booleans are converted.
What happens to namespaces and prefixes?
Element and attribute names are kept exactly as written, including prefixes such as atom:link. Namespace declarations appear as attributes like @xmlns:atom.
Are comments and processing instructions converted?
No. Comments, the XML declaration and processing instructions carry no data and are left out.
What does “not well-formed” mean?
The document breaks a basic rule of XML: a tag is not closed, tags overlap, an attribute value is not quoted, an ampersand is not escaped, or there is more than one root element. The message shows where the parser stopped.
What changes when XML becomes JSON
XML was designed for documents and adapted for data; JSON was designed for data from the start. Converting from one to the other means deciding how features that exist only in XML should appear in a format that lacks them. The decisions made here follow the convention used by most libraries, which keeps the output familiar and makes conversion back to XML possible.
An element with only text becomes a string. An element with child elements becomes an object whose keys are the child names. Attributes, which JSON has no place for, are stored as keys with an @ prefix so that they cannot collide with child elements of the same name. When an element has both attributes and text, the text goes under #text.
Lists are inferred from repetition. XML has no array syntax, so the only evidence of a list is that an element name occurs several times. This inference is correct almost always but has one blind spot: a list that happens to contain a single entry looks like a single object. Code that consumes the JSON should be written with that in mind.
Some information does not survive. The order of different sibling elements is lost when they are grouped by name, comments are dropped, and the distinction between a CDATA section and ordinary text disappears. For data-oriented XML, such as feeds, API responses and configuration files, none of this matters. For document-oriented XML with mixed content, where text and elements interleave within a paragraph, JSON is a poor fit and the result should be checked carefully.