JSON ↔ XML Converter
Bidirectional conversion. Handles @attributes, #text, arrays, pretty print, and XML declaration.
How to Use the JSON ↔ XML Converter
- Select direction — choose JSON→XML or XML→JSON using the chips at the top.
- Paste your data — put JSON or XML into the input area on the left.
- Configure options — enable pretty print, XML declaration, or minify as needed.
- View the result — the converted output appears instantly on the right.
- Copy or download — use the buttons above the output to export your result.
JSON and XML Conversion Conventions
Converting between JSON and XML requires conventions because the two formats have fundamentally different data models. JSON supports objects (key-value pairs), arrays, strings, numbers, booleans, and null. XML supports elements, attributes, text content, namespaces, comments, and mixed content. This tool uses a widely-adopted convention to bridge the gap.
Object Keys Become Element Names
Each JSON object key becomes an XML element name. The value of the key becomes the element's text content (for primitives) or child elements (for nested objects). Key names must be valid XML element names — they should start with a letter or underscore and contain only letters, digits, hyphens, underscores, and periods. Keys starting with numbers will be prefixed automatically.
The @attribute Convention
JSON keys that start with @ are treated as XML attributes. For example, the JSON {"user": {"@id": "42", "name": "Alice"}} converts to <user id="42"><name>Alice</name></user>. When converting XML back to JSON, any XML attributes are represented with the @ prefix in the resulting JSON object.
The #text Convention
When an element has both attributes and text content, the text content is stored in a JSON key named #text. For example, <price currency="USD">9.99</price> becomes {"price": {"@currency": "USD", "#text": "9.99"}}. This allows the distinction between an element's attributes and its content to be preserved in JSON.
Arrays as Repeated Elements
JSON arrays are represented in XML as repeated elements with the same tag name. The JSON {"items": {"item": ["A", "B", "C"]}} becomes three <item> elements inside an <items> element. Conversely, when parsing XML, sibling elements with the same tag name are combined into a JSON array. This is the most common convention and is used by popular libraries like fast-xml-parser and xml2js.
XML Declaration
The XML declaration <?xml version="1.0" encoding="UTF-8"?> is an optional prologue for XML documents. It is required when the XML document will be used as a standalone file. It is typically omitted for XML fragments embedded inside other documents or sent as part of a SOAP request body. Enable the "XML declaration" chip to include it.
When to Use Each Format
Use JSON for REST APIs, JavaScript applications, configuration files, and any context where human readability and browser compatibility matter. Use XML when working with SOAP web services, RSS/Atom feeds, SVG graphics, Android layouts, Microsoft Office documents, or systems that require formal schema validation with DTD or XSD. Many enterprise integration platforms (MuleSoft, BizTalk, IBM Integration Bus) work primarily in XML and require JSON-to-XML conversion when integrating with modern APIs.