JSON ↔ XML Converter
Convert JSON into clean, indented XML, or parse XML — with attributes preserved — back into pretty-printed JSON, all in your browser.
Everything runs in your browser — your data is never uploaded to a server.
Understanding the JSON ↔ XML Converter
A bidirectional JSON ↔ XML converter for developers. Transform JSON objects into formatted, indented XML with proper element nesting, or parse XML markup (with attributes preserved) back into pretty-printed JSON. All conversion happens client-side in your browser — your data never leaves your device.
How it works
The tool uses the fast-xml-parser library (XMLBuilder and XMLParser). For JSON→XML conversion, it parses the input JSON string, validates it's an object or array, then builds formatted XML with 2-space indentation. For XML→JSON, it parses the XML string, validates structure, and returns prettified JSON with 2-space indentation. XML attributes are mapped to JSON keys prefixed with @_ and vice versa, ensuring lossless round-trip conversion.
Worked example
Input JSON: {"note": {"@_id": "1", "to": "Ann", "from": "Bob", "body": "Hello there"}} converts to: <note id="1"><to>Ann</to><from>Bob</from><body>Hello there</body></note>. Reverse it: the XML parses back to the original JSON structure with the id attribute preserved as @_id.
Tips & common mistakes
- XML attributes must be prefixed with @_ in your JSON to round-trip correctly (e.g., @_id becomes the id attribute in XML).
- Your JSON input must be an object or array, not a primitive value — a bare string or number cannot map to XML elements.
- The output XML is formatted with 2-space indentation for readability; paste it elsewhere if you need compact single-line output.
- When parsing XML to JSON, all attributes and text content are preserved; namespaces and CDATA sections are handled by the parser.
- If your XML has no root element or is malformed (unclosed tags, mismatched pairs), conversion will fail with a specific error message.
- Use the Download button to save output as .xml or .json files directly to your device.
Related tools
Frequently Asked Questions
Does it handle XML attributes?
Yes. XML attributes are preserved in both directions. When converting XML to JSON they appear as keys prefixed with @_, and JSON keys written as "@_id" are emitted back as real XML attributes.
Does it convert both directions?
Yes. Use the mode toggle to switch between JSON → XML, which builds formatted, indented XML, and XML → JSON, which parses your markup into pretty-printed JSON.
Is my data uploaded anywhere?
No. All parsing and conversion happen locally in your browser using JavaScript. Your JSON and XML never leave your device and nothing is sent to a server.