XML to JSON Converter with Attribute and Array Control
Convert XML to JSON with attribute prefixes, array rules, CDATA and namespace handling. DOCTYPE entities are never expanded. Runs in your browser.
Runs in your browser. Nothing is uploaded.
ConvertersXML to JSON
XML
Max 50MB each
Comma separated; applies in both array modes
Result
Paste XML on the left, or load the sample. JSON appears here as you type.
Example
<book id="b1"><title>XML & You</title><tag>a</tag><tag>b</tag></book>
{
"book": {
"@id": "b1",
"title": "XML & You",
"tag": ["a", "b"]
}
}How the mapping works
XML and JSON model data differently, so any converter makes choices. Here an element becomes a key, nested elements become nested objects, and an element that repeats becomes an array. Attributes are written as keys with a prefix (@ by default, any prefix you type), grouped under one @attributes key, or dropped. When an element has attributes or children and also text, the text goes under a text key named #text unless you rename it.
The single-item problem is the classic trap: one <item> becomes an object while two become an array, which breaks code that loops over the result. Choose "every child is an array", or list tag names such as item, row that must always be arrays. CDATA sections can be merged into the text or kept under a #cdata key, comments are dropped unless you keep them, and XML declarations are left out unless you ask for them.
Types, namespaces and mixed content
With type detection on, numbers and the words true and false become JSON values in text and attributes, while values with leading zeros and numbers with more than 15 digits stay text so identifiers survive. Numeric character references such as A are decoded along with the five standard entities.
Namespace prefixes stay in the names (s:Envelope) because they carry meaning; use the strip option when you only want local names. Namespace declarations stay as attributes. Mixed content such as <p>Hello <b>big</b> world</p> cannot be expressed as a plain object without losing the order of text and elements, so use the "preserve order" option, which produces an ordered array of nodes instead.
Security, errors and limits
XML can declare custom entities in a DOCTYPE, and a "billion laughs" file uses nested entities to expand a few hundred bytes into gigabytes, while external entities can make a naive parser read local files (XXE). This tool never expands them: the DOCTYPE is blanked out before parsing, with line breaks kept so error line numbers still match, and a warning tells you what was ignored. References to custom entities stay as literal text. Elements named __proto__ are refused, and extremely deep nesting is rejected.
Malformed XML is validated first, so errors carry an exact line and column with an excerpt, for example a closing tag that does not match the opening tag or a repeated attribute. Inputs over about a megabyte are converted in a background worker. The tool reads documents, not schemas: it does not validate against an XSD or DTD, and it is not meant for streaming files of hundreds of megabytes.
Frequently asked questions
Why is a single element an object but two become an array?
That is how repeated tags are detected. Choose "every child is an array" or list tag names under "Always arrays" so the shape is stable.
How are attributes represented?
By default as keys with an @ prefix next to the child elements. You can change the prefix, group them under @attributes, or leave them out.
Is it safe against XML entity bombs?
Yes. The DOCTYPE is ignored, so custom and external entities are never expanded. Only the five standard entities and numeric character references are decoded.
What happens to mixed text and elements?
In the default object form the order is lost. Turn on "Preserve order" to get an ordered array of text and element nodes.
Does it validate against an XSD?
No. It checks that the XML is well-formed and reports the line and column of the first error, but it does not validate against a schema.
