XML to JSON
Map XML elements, attributes and repeated children into explicit JSON locally.
How it works & useful details
JSON mapping
The root element becomes the single top-level JSON property. Attributes become keys prefixed with @; text becomes #text when an element also has attributes or children; sibling elements with the same name become arrays.
XML has no native JSON number or boolean types, so element text and attributes remain strings. DTD/entity declarations are rejected.
Private, bounded processing
This workspace parses text only in your browser. It never opens links, requests external entities, runs pasted configuration, or saves your document. Input is limited to 500,000 characters; conversion output is limited to 1,000,000 characters.
About this tool
XML to JSON maps elements, attributes, and repeated children into explicit JSON using documented conventions. It helps when you need to feed XML data into JavaScript tooling without pulling in a parser library.
The mapping is deliberate rather than automatic: attributes and text content are marked explicitly so information is not silently lost. Parsing is local, and external entities or remote documents are never fetched.
How to use it
- Paste the XML document.
- Convert to see the documented JSON representation.
- Check the notes for attributes, repeated elements, and mixed content.
- Copy the JSON or download it.
Worked example
<profile id="a1"><name>Ada</name><tag>math</tag><tag>code</tag></profile>converts to
{
"profile": {
"@id": "a1",
"name": "Ada",
"tag": ["math", "code"]
}
}The attribute becomes @id, and the two <tag> siblings become an array. A single <tag> would become a plain string, so code that reads the JSON should accept both shapes. This is a known trade-off of every XML-to-JSON mapping.
Working with the result
All values stay strings: <port>8080</port> becomes "8080", because XML itself has no number or boolean types unless a schema defines them. When an element has both attributes and text, such as <price currency="EUR">19.99</price>, the text is stored under #text next to @currency.
Converting XML to JSON is handy when inspecting plain XML exports and API responses in JavaScript tools, loading legacy exports into document databases, or comparing two XML files with JSON compare. The mapping mirrors JSON to XML, so an edited result can be converted back.
Frequently asked questions
How are attributes represented?
Attributes are kept in a separate, documented key so element names and attribute names cannot collide.
What happens to repeated elements?
Repeated children become arrays, preserving order and count.
What is the limit?
Up to 500,000 characters of XML input.
Are namespaces supported?
No. Prefixed names such as soap:Envelope are rejected with a clear message, because mapping namespaces to JSON keys is ambiguous. The converter is meant for plain data XML.
