XML ↔ JSON Converter
Convert XML and JSON data bidirectionally, preserving attributes and text.
Category: Converters
When to use?
Use it to turn XML API responses or config files into easier-to-handle JSON, or to fit JSON data to a system requiring XML.
How to use
- Choose the direction (XML → JSON or JSON → XML).
- Paste the data into the input.
- Review and copy the result.
Input Explanation
XML must have properly closed tags, and JSON must have a single top-level object. Attributes use @ keys and text content uses the #text key.
Calculation Basis
XML → JSON parses elements, attributes, and text into objects with the DOM parser, grouping repeated tags into arrays. JSON → XML turns @-prefixed keys into attributes and others into child elements.
Usage Examples
- Handle API responses - Convert XML API responses into easier-to-handle JSON.
- Convert config files - Convert XML config to use in JSON-based tools.
- Integrate legacy systems - Fit JSON data to a system that requires XML.
Examples
- <book category="tech">…</book> → { "book": { "@category": "tech", … } }
- Repeated tags become a JSON array
Cautions
- Malformed source data can cause parsing errors or broken output.
- A mismatched encoding standard or complex nested data may break or drop the structure.
Guides
Attribute and text rules
XML attributes use an @ prefix on the key, and an element's text content uses the #text key. Repeated tags are grouped into an array.
JSON → XML input condition
XML needs one root element, so input an object with a single top-level key. @-prefixed keys are converted to attributes.
FAQ
How are XML attributes represented?
Attributes are prefixed with @. E.g. category="tech" → "@category": "tech".
What if the same tag repeats?
Repeated identical tags are grouped into a JSON array.
What to watch for in JSON → XML?
XML needs one root, so input an object with a single top-level key.
What happens on a syntax error?
If the XML or JSON is malformed, a message points out what to check.
Related Tools
- YAML ↔ JSON Converter - Convert YAML and JSON data bidirectionally in the browser.
- JSON Formatter - Beautify or minify JSON strings instantly and check for validity errors.
- CSV ↔ JSON Converter - Convert CSV and JSON array data bidirectionally.
- XML Formatter - Parse an XML document and indent it by hierarchy.
- TOML ↔ JSON Converter - Convert TOML config and JSON data bidirectionally in the browser.
- URL Encode / Decode - Encode text into URL-safe form (%XX) or decode an encoded URL back to text.