XML vs JSON
XML is verbose but strict — it has attributes, namespaces and a formal spec. JSON is compact and native to JavaScript. Most modern systems speak JSON, but legacy enterprise systems (SOAP, RSS, config exports) still emit XML — hence the eternal converter. This tool handles the practical subset: elements, attributes, text, nesting, and CDATA-ish text content.
Conversion rules used here
- Attributes become keys prefixed with
@(e.g.@id) so they never collide with child elements. - Text content becomes
#textwhen an element has both attributes and children. - Repeated elements become arrays.
- JSON → XML reverses the mapping:
@key→ attribute,#text→ text content.
Formatting & validation
Format pretty-prints any XML with proper indentation using the browser's DOMParser (and reports parse errors with line hints). Validate checks well-formedness — not schema validity (that needs an XSD; no way to do it fully static). For config-family formats see YAML and TOML tools.
Formats, sizes and other limits
xmlToObj() walks the DOM produced by DOMParser: attributes become keys with an @ prefix, child elements become nested objects, text content is captured per node, and repeated sibling names collapse into arrays so a list of items does not lose entries. objToXml() runs the same conventions backwards, and formatXml() pretty-prints the result. Choosing a convention explicitly is the whole problem with XML-to-JSON — there is no canonical mapping.
Where it stops working
Namespaces are flattened to their prefixes, so two elements with the same local name in different namespaces can collide. Mixed content — text interleaved with child elements — loses the ordering, because JSON objects have no notion of position. Comments, processing instructions and the XML declaration are dropped. Entities beyond the predefined five are resolved by the parser before conversion, which can surprise you with large documents.
Privacy: nothing is uploaded
The document is parsed with the browser’s own DOMParser locally; no XML, namespace or attribute leaves the page and nothing is cached.
Frequently asked questions
Why did my attributes get an @ prefix?
Because JSON has no attribute concept. The prefix keeps them distinguishable from child elements — a convention, not a standard.
What happens to mixed content?
Ordering between text and child elements is lost. JSON cannot represent interleaving, so a paragraph with inline markup comes back simplified.
Are namespaces preserved?
Only as prefixes. Two same-named elements from different namespaces can therefore collide after conversion.