XML & JSON Converter
Convert between XML and JSON formats online with customizable options
About XML and JSON
XML (Extensible Markup Language) and JSON (JavaScript Object Notation) are two of the most commonly used data exchange formats. XML is time-tested with rigorous structure, widely used in enterprise applications and web services; JSON is lightweight and concise, the preferred format for modern web APIs. This tool helps you quickly convert between the two formats.
This tool supports advanced options like custom attribute prefixes and text node keys, plus XML/JSON formatting and minification for easy data format conversion.
Conversion Rules
XML and JSON structures don't map perfectly. Conversion follows these rules:
- Attribute Handling:XML element attributes are converted to JSON object keys, using @ prefix by default (customizable). For example,
becomes {"@src":"a.png"}. - Array Handling:When multiple same-named child elements exist under the same parent, they are automatically converted to a JSON array. For example, multiple
- elements become "item": [...] array format.
- Text Nodes:XML element text content is stored using a specified key name (default #text). For example,
Zhang becomes {"#text":"Zhang"}. - CDATA Handling:CDATA sections in XML are treated as plain text, with content preserved in the corresponding text key.
FAQ
Can XML converted to JSON be converted back?
Yes. The conversion preserves all information (attributes, text, hierarchy), and reverse conversion can restore the original XML structure. Attribute prefix and text key name must remain consistent in both directions.
Is data uploaded to a server?
No. All conversions are done locally in your browser using DOMParser and JavaScript. Data is never sent to any server.
Does it support complex nested XML?
Yes. The tool handles arbitrary nesting depth, including mixed content (nodes containing both child elements and text), namespaces, CDATA sections, and more.
Can the attribute prefix be customized?
Yes. The default attribute prefix is @, but you can change it to other prefixes ($, -, etc.) in the conversion options, or leave it empty to use no prefix.