XML to JSON Converter
- Runs on your device
- Nothing uploaded
- Free, no sign-up
How XML maps to JSON here
Element names become object keys. Repeated sibling tags become arrays. Text content becomes string values. Attributes are preserved with a conventional prefix when present. Mixed content (text and child elements together) is lossy compared to a full XML infoset.
JSON back to XML rebuilds elements from keys; arrays become repeated tags. Attribute round-trips depend on the prefix convention this page uses.
Worked example: a simple note element
XML:
<note>
<to>Cobra</to>
<from>ToolPetal</from>
<body>Hello</body>
</note>
JSON shape:
{"note":{"to":"Cobra","from":"ToolPetal","body":"Hello"}} Limits
Namespaces, DTDs, XSD validation, and entity expansion are not full XML processor features here. Huge documents may freeze the tab. Prefer dedicated XML tooling for SOAP or publishing pipelines.
Attributes and arrays
When an element repeats, JSON needs an array. When it appears once, many converters emit a bare object. That asymmetry surprises APIs that always expect arrays. If your producer sometimes sends one item and sometimes many, normalize to arrays in your own code after conversion.
Attributes are not first-class JSON. This page keeps them with a documented prefix convention so you can map them back when generating XML again.
Worked example: attributes and repeated elements
Input <book id="7"><title>Dune</title><tag>sf</tag><tag>classic</tag></book>. The id attribute and the title element both become keys, and the two tag elements become an array. XML has no standard JSON mapping, so check how attributes are named in the output before you write code against it.
Pitfalls
- One vs many. A single
<tag>often becomes a string while two become an array. Code that reads the JSON should handle both shapes. - Everything is text. XML has no number or boolean types, so
7may come out as the string "7". Convert types in your code. - Namespaces. Prefixes like
dc:titleare kept as part of the key name.
FAQ
Does XML to JSON upload my markup?
No. Parsing and conversion run locally.
Will round-trip preserve everything?
Simple element trees round-trip well. Mixed content, comments, and some namespace edge cases may not.
How are repeated tags handled?
Sibling elements with the same name become a JSON array.
Can I convert JSON to XML?
Yes. Use the direction control on this page. Arrays become repeated elements.
Why is my single child not an array?
With only one repeated element, the converter cannot know it is meant to be a list. Normalize it to an array in your code.
Does the converter keep XML comments?
JSON has no comments, so XML comments are not part of the output.