JSON ↔ XML Converter

Bidirectional conversion. Handles @attributes, #text, arrays, pretty print, and XML declaration.

JSON Input
XML Output
Paste JSON or XML above and select a direction.

How to Use the JSON ↔ XML Converter

  1. Select direction — choose JSON→XML or XML→JSON using the chips at the top.
  2. Paste your data — put JSON or XML into the input area on the left.
  3. Configure options — enable pretty print, XML declaration, or minify as needed.
  4. View the result — the converted output appears instantly on the right.
  5. 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.

Frequently Asked Questions

Paste your JSON into the input area, select JSON→XML mode, and click Convert. JSON object keys become XML element names. Arrays become repeated elements. Values become text content.
Use keys prefixed with @ to represent XML attributes. For example, {"element": {"@id": "1", "#text": "Hello"}} converts to <element id="1">Hello</element>. The #text key holds the element's text content.
Each array item becomes a separate XML element with the same tag name. {"items": {"item": ["A","B"]}} becomes <items><item>A</item><item>B</item></items>.
Yes. Enable the "XML declaration" chip to prepend <?xml version="1.0" encoding="UTF-8"?> to the output. Required for standalone XML files, optional for fragments.
JSON is lighter, easier to read, and maps directly to JavaScript objects — the dominant format for REST APIs. XML is more verbose but supports attributes, namespaces, and has mature validation tooling (DTD, XSD). Many enterprise and legacy systems still use XML, especially SOAP services.