JSON
XML

How to convert JSON to XML

  1. Paste your JSON object into the input field — a single root object whose keys become XML element names.
  2. Click "Convert" — the formatted XML output appears instantly with proper indentation and an XML declaration.
  3. Switch to "XML → JSON" using the toggle above if you need the reverse direction.
  4. Click "Copy" or "Download .xml" to use the output in your system, API, or configuration file.
  5. Use @attributes in your JSON to produce XML element attributes — see the mapping reference below.

How the JSON to XML converter works

The converter traverses the JSON object recursively and maps each key-value pair to an XML element. String and number values become element text content. Nested objects become child elements. Arrays are expanded into repeated sibling elements with the parent key as the tag name. The special key @attributes produces XML attributes on the parent element; the special key #text produces mixed text content alongside attributes. The output includes an XML declaration and is indented for readability.

The @attributes convention makes the conversion reversible — JSON produced by the XML to JSON converter can be converted back to XML and produce the same structure. The conversion runs entirely in your browser — no data leaves your machine.

JSON object → XML document conversion
// Input JSON:
{
  "users": {
    "user": [
      { "@attributes": { "id": "1" }, "name": "Alice", "city": "Kyiv" },
      { "@attributes": { "id": "2" }, "name": "Bob",   "city": "Lviv" }
    ]
  }
}

// Output XML:
<?xml version="1.0" encoding="UTF-8"?>
<users>
  <user id="1">
    <name>Alice</name>
    <city>Kyiv</city>
  </user>
  <user id="2">
    <name>Bob</name>
    <city>Lviv</city>
  </user>
</users>

Who uses JSON to XML conversion

JSON is the primary data format for modern web APIs. XML is the required format for enterprise integrations, legacy systems, and certain configuration tools. Converting JSON to XML bridges these two generations of technology.

  • SOAP API integration — building request payloads for SOAP or XML-RPC web services from JSON data in a JavaScript or Node.js application.
  • Enterprise message bus — formatting messages for systems that use XML-based message formats (JMS, MQ, ESB, EDI).
  • Configuration file generation — creating XML config files (Maven pom.xml, Spring beans, Android resources) from JSON-based build data.
  • Data export to legacy systems — converting modern API responses to XML for import into ERP, CRM, or accounting systems that require XML.
  • Sitemap generation — building XML sitemaps from a JSON list of URLs and metadata.
  • Office document creation — generating OOXML fragments (Excel, Word) from structured JSON data for reporting pipelines.

JSON to XML mapping conventions

The converter follows a set of mapping conventions for the JSON-to-XML direction. Understanding these conventions lets you structure your JSON input to produce exactly the XML output you need.

JSON inputXML outputNotes
"tag": "text"<tag>text</tag>String value → text content
"tag": 42<tag>42</tag>Number value → text content (stringified)
"tag": true<tag>true</tag>Boolean value → text content
"tag": null<tag/>null → self-closing empty element
"tag": { "child": "v" }<tag><child>v</child></tag>Object → child elements
"tag": ["a", "b"]<tag>a</tag><tag>b</tag>Array → repeated sibling elements
"@attributes": { "id": "1" }id="1" on parent element@attributes → XML attributes
"#text": "content"text content alongside attributes#text → mixed element text content

When to convert JSON to XML — and when to keep JSON

Convert to XML when:

  • Target system requires XML — SOAP services, enterprise message buses, and legacy APIs that only accept XML-encoded payloads.
  • Document markup is needed — XML supports mixed content (text interleaved with elements) used in document formats like DocBook, TEI, and OOXML.
  • Configuration files must be XML — Maven, Spring, Android resources, and many Java ecosystem tools use XML as their config format.
  • XSLT transformation pipeline — XSLT processing requires XML input; the JSON needs to become XML before it can be transformed.
  • Schema validation is required — XML Schema (XSD) and RelaxNG provide strict structural validation that JSON Schema does not match in all enterprise contexts.

Keep JSON when:

  • Target is a REST API or JavaScript application — JSON.parse() is native; XML adds unnecessary parsing overhead.
  • Payload size matters — JSON is typically 20–40% smaller than equivalent XML due to the absence of closing tags.
  • Data has arrays of uniform objects — JSON arrays are cleaner than repeated XML elements with no semantic distinction.
  • NoSQL databases are the destination — MongoDB, Firestore, and DynamoDB store JSON-like documents natively.

Building valid XML: element names and special characters

XML has stricter naming and encoding rules than JSON. When structuring the JSON input for conversion, keep these XML constraints in mind to avoid invalid output:

  • Element names must start with a letter or underscore — JSON keys that start with a digit (like "1item") produce invalid XML. Rename such keys before converting.
  • No spaces in element names — JSON keys with spaces ("first name") cannot become valid XML tags. Use camelCase or underscore-separated keys instead.
  • Special characters in text content are escaped — the converter automatically escapes &, <, >, ", and ' in text values to &amp;, &lt;, &gt;, &quot;, and &apos;.
  • The JSON root must be a single object — JSON arrays at the root level are not valid because XML requires exactly one root element. Wrap arrays in an object: { "items": [...] }.
  • Attribute values are strings — the @attributes object should contain only string or number values; nested objects inside @attributes are not valid.
Using @attributes and #text in JSON input
// JSON with @attributes for element attributes
// and #text for mixed content:
{
  "product": {
    "@attributes": { "id": "P001", "currency": "USD" },
    "name": "Wireless Headphones",
    "price": {
      "@attributes": { "sale": "true" },
      "#text": "49.99"
    },
    "tags": ["audio", "wireless", "bluetooth"]
  }
}

// Output XML:
<?xml version="1.0" encoding="UTF-8"?>
<product id="P001" currency="USD">
  <name>Wireless Headphones</name>
  <price sale="true">49.99</price>
  <tags>audio</tags>
  <tags>wireless</tags>
  <tags>bluetooth</tags>
</product>

Frequently Asked Questions

What JSON structure does the converter expect?
The converter expects a single JSON object at the root level — the top-level key becomes the XML root element name. Arrays at the root are not supported because XML requires exactly one root element. Wrap an array in a root object: { "items": [ ... ] }.
How do I add attributes to XML elements?
Add a key named @attributes to the JSON object at the level of the element you want to add attributes to. Its value must be an object of attribute name–value pairs: { "@attributes": { "id": "1", "class": "active" } }. The converter converts these to XML attributes on the parent element.
How do I produce an element with both attributes and text content?
Use both @attributes and #text in the same object: { "@attributes": { "currency": "USD" }, "#text": "9.99" }. This produces <price currency="USD">9.99</price>. Without @attributes, a string value is sufficient: "price": "9.99" produces <price>9.99</price>.
How are JSON arrays converted to XML?
A JSON array value produces repeated sibling elements with the same tag name — the parent key becomes the element name for each item. { "tag": ["a", "b", "c"] } produces <tag>a</tag><tag>b</tag><tag>c</tag>. An array of objects produces sibling elements with the same structure for each item.
What happens to null values in JSON?
null values produce self-closing empty elements. "description": null becomes <description/>. If you want an element to be omitted entirely, remove the key from the JSON object before converting.
Are special characters in values automatically escaped?
Yes. The converter automatically escapes the five XML reserved characters in text content and attribute values: & → &amp;, < → &lt;, > → &gt;, " → &quot;, ' → &apos;. You do not need to pre-escape your JSON values.
My JSON keys start with numbers or contain spaces — will the XML be valid?
No. XML element names must start with a letter or underscore, and cannot contain spaces. JSON keys that violate these rules will produce invalid XML tag names. Rename such keys before converting: "1item" → "item1", "first name" → "firstName".
Does the output include an XML declaration?
Yes. The converter adds <?xml version="1.0" encoding="UTF-8"?> as the first line of the output. This is standard practice for standalone XML documents and is expected by most XML parsers and validators.
Can I produce XML with namespaces?
Yes. Add namespace declarations as @attributes entries and use prefixed key names. For example: { "@attributes": { "xmlns:ns": "http://example.com" }, "ns:item": "value" } produces <root xmlns:ns="http://example.com"><ns:item>value</ns:item></root>.
What is the maximum JSON file size the converter handles?
There is no server-side limit — the conversion runs entirely in your browser. Practical limits are set by your browser's memory. JSON files up to several megabytes convert without issue on modern devices.
Is any data sent to a server during conversion?
No. The entire conversion runs in your browser using JavaScript. No data is transmitted over the network — there are no privacy concerns and no file size limits.
Can I convert the XML back to JSON?
Yes — switch to "XML → JSON" using the toggle above the tool. If your JSON follows the @attributes and #text conventions, the round-trip is lossless for most structures.