"category": "format-converter",
JSON to XML Converter
"tldr": Paste JSON and get well-formed XML with proper escaping - arrays become repeated elements, keys become tags, output always parses.
Convert JSON into well-formed XML for SOAP services, legacy enterprise systems, RSS feeds, or any integration that still speaks XML. Object keys become element names, arrays become repeated elements, and special characters (&, <, >, ") are escaped so the output always parses.
Keys that are not valid XML element names are sanitized automatically, and the whole document is wrapped in a root element as XML requires. Conversion happens locally in your browser - nothing is sent to a server.
How to convert JSON to XML
- 1Paste your JSON into the input panel.
- 2Object keys become XML element names; invalid characters in keys are replaced with underscores.
- 3Arrays produce one element per item with the same tag name, which is the standard XML pattern.
- 4Copy the XML output or download it as an .xml file.
Convert JSON to XML in code
import json
from dicttoxml import dicttoxml # pip install dicttoxml
with open("data.json") as f:
data = json.load(f)
xml = dicttoxml(data, custom_root="root", attr_type=False)
print(xml.decode())import { js2xml } from "xml-js"; // npm install xml-js
const data = JSON.parse(jsonString);
const xml = js2xml({ root: data }, { compact: true, spaces: 2 });Frequently asked questions
How are JSON arrays represented in XML?
Each array item becomes a repeated element with the same tag. For example {"regions": ["a", "b"]} produces <regions>a</regions><regions>b</regions>. This is the convention virtually all XML consumers expect.
Why is everything wrapped in a <root> element?
XML requires exactly one top-level element, while JSON allows a bare array or multiple top-level keys. The converter adds a <root> wrapper to guarantee well-formed output; rename it to whatever your schema expects.
What about XML attributes?
JSON has no concept of attributes, so all values become element content - the unambiguous representation. If your target schema requires attributes, convert first and then adjust the specific elements, or use a mapping library with an attribute convention like @name.
Are special characters escaped?
Yes. Ampersands, angle brackets, and quotes in your values are escaped to &, <, >, and " so the output is always valid XML, even when your JSON contains HTML fragments or URLs with query strings.
Last updated:
You might also need
Free and in-browser, like everything on JSON Console. Browse all tools →