XML to JSON
XML to JSON uses fast-xml-parser with attributes retained under @-prefixed names, then prints the object. XML and JSON data models do not align uniquely: repeated elements can become arrays, mixed content/order may be surprising, and namespaces are not turned into a semantic schema. No XSD validation, XPath, canonicalization, or reversible mapping is provided.
Runs locally — files stay on your deviceHow are XML attributes represented?
Their keys use an @ prefix.
XML-to-object mapping is a convention
Elements, attributes, text, namespaces, order, and mixed content require explicit mapping rules.
How it works
XMLParser uses ignoreAttributes=false and @ prefix; JSON.stringify emits two-space output.
Key concepts
Attributes get @ keys
This is a library convention.
Repeated elements may be arrays
Multiplicity affects output shape.
When to use it
- Inspect a simple XML document.
- Create a JSON debugging view.
- Convert controlled XML under this convention.
When not to use it
- Do not expect exact round trips.
- Do not rely on it for XSD validity.
- Do not assume mixed-content order preservation.
Worked examples
Attribute
- Input
<item id="1">A</item>- Expected output
Object with @id
Configured convention.
Repeated
- Input
<r><x>1</x><x>2</x></r>- Expected output
x array
Occurrences affect type.
Mixed
- Input
<p>Hello <b>x</b> world</p>- Expected output
Nontrivial shape
Ordered mixed content is complex.
Common mistakes
Guessing shape
Multiplicity changes types. Correction: Test representative XML.
Ignoring namespaces
Names stay lexical keys. Correction: Apply namespace-aware logic.
Calling it validation
No XSD is used. Correction: Validate separately.
Best practices
- Test attributes, repeats, empties, and mixed content.
- Document the mapping.
- Validate production XML.
Related operations and differences
JSON to XML
Choose JSON to XML when you need to convert JSON objects into formatted XML.; use XML to JSON specifically for xml to json.
CSV to JSON
Choose CSV to JSON when you need to convert a header-based CSV table to JSON.; use XML to JSON specifically for xml to json.
JSON to CSV
Choose JSON to CSV when you need to convert an array of JSON objects to CSV.; use XML to JSON specifically for xml to json.
JSON to YAML
Choose JSON to YAML when you need to convert JSON data into readable YAML.; use XML to JSON specifically for xml to json.
YAML to JSON
Choose YAML to JSON when you need to convert YAML data into formatted JSON.; use XML to JSON specifically for xml to json.
CSV to TSV
Choose CSV to TSV when you need to convert comma-separated data to tab-separated data.; use XML to JSON specifically for xml to json.
Limitations and privacy
- No XSD/DTD validation, XPath, namespace semantics, canonicalization, streaming, mapping controls, or guaranteed round trip.
The pasted data is parsed and transformed locally in this browser.
Frequently asked questions
Are attributes ignored?
No.
Is XSD applied?
No.
Can repeated tags become arrays?
Yes.
Is conversion reversible?
Not reliably.