AllOneTools Logo
AllOneTools

JSON → XML

Convert JSON to XML online

Transform JSON into clean, well-formed XML. Configure root element, attribute handling, and array naming. In-browser, privacy-first, no signup.

Last updated:

[object Object]

[object Object]

[object Object]

Open the JSON → XML converter

Runs entirely in your browser. No signup, no upload.

Launch converter →

Example: JSON → XML

Input (.json)

{
  "bookstore": {
    "books": [
      { "title": "Clean Code", "author": "Robert C. Martin", "year": 2008 },
      { "title": "The Pragmatic Programmer", "author": "Hunt & Thomas", "year": 1999 }
    ]
  }
}

Output (.xml)

<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
  <books>
    <item>
      <title>Clean Code</title>
      <author>Robert C. Martin</author>
      <year>2008</year>
    </item>
    <item>
      <title>The Pragmatic Programmer</title>
      <author>Hunt &amp; Thomas</author>
      <year>1999</year>
    </item>
  </books>
</bookstore>

How to convert JSON to XML manually

Prefer scripting this in a pipeline? Here are the most common CLI and library approaches.

Python with dict2xml

from dict2xml import dict2xml
import json
xml = dict2xml(json.load(open('in.json')))
open('out.xml','w').write(xml)

Node.js with xml-js

const xmljs = require('xml-js');
const json = require('./in.json');
const xml = xmljs.js2xml(json, { compact: true, spaces: 2 });

Java (Jackson)

XmlMapper xml = new XmlMapper();
ObjectMapper json = new ObjectMapper();
JsonNode tree = json.readTree(new File("in.json"));
xml.writeValue(new File("out.xml"), tree);

Frequently asked questions

Why do my array items become `<item>` tags?

XML elements require names, and JSON arrays don't provide one. We use `<item>` as a safe default. If your parent key is e.g. `books`, you can post-process the XML to rename `<item>` to `<book>` — or tell us in the options to singularize automatically.

How are attributes (`@foo`) handled?

If a JSON key starts with `@`, we emit it as an XML attribute on the parent element. So `{ "item": { "@id": "5", "name": "X" } }` becomes `<item id="5"><name>X</name></item>`. This follows the badgerfish / JsonML conventions most XML libraries already use.

Does it escape special characters correctly?

Yes. `<`, `>`, `&`, `'`, and `"` are escaped using standard XML entities (`&lt;`, `&gt;`, `&amp;`, etc.) in text nodes and attribute values. The output is valid XML 1.0.

Can I add an XML namespace?

Include `"@xmlns": "http://example.org/schema"` on any object key; the converter emits it as a namespace declaration. For prefixed namespaces, use `"@xmlns:ns": "..."` and prefix child keys with `ns:`.

Is the output valid against an XSD schema?

We emit well-formed XML — not schema-valid XML. If you have an XSD you need to match, paste the result into our XML Validator to check conformance.

Related tools & guides