JSON to XML Converter

Paste JSON Data

Paste valid JSON data (objects, arrays, etc.)

Upload Your JSON Files

Drag & drop your .json files here or click to browse

Supported format: JSON

What Does This JSON to XML Converter Do?

AllFileTools' JSON to XML Converter transforms JSON objects, arrays, and all native data types into valid, properly structured XML instantly. You can paste raw JSON text, upload a .json or .txt file, or batch-convert multiple files at once. The tool handles nested objects, JSON arrays, boolean values, null values, numbers, and XML attribute mapping — producing download-ready XML output every time.


How to Convert JSON to XML Online

Step 1: Paste your JSON into the input box — or click Upload File to select a .json file from your device.

Step 2: Click the Convert button. The tool validates your JSON, then generates clean, indented XML automatically.

Step 3: Click Copy to copy the XML to your clipboard, or click Download to save the .xml file directly.

That's it. No configuration required for standard conversions.


How to Convert JSON to XML

If you want to convert JSON to XML manually — without writing code — paste your JSON into the input box above and click Convert. The tool maps each JSON key to an XML element and each value to element content. For programmatic conversion using Python, JavaScript, Java, or C#, see the code examples further down this page.


Why Convert JSON to XML? Real-World Use Cases

Modern systems overwhelmingly use JSON, but a large portion of enterprise, healthcare, and financial infrastructure still requires XML. Understanding when and why you need to convert is as important as knowing how.


SOAP API Integration

SOAP (Simple Object Access Protocol, W3C SOAP 1.1/1.2 specification) requires XML-formatted messages wrapped in a SOAP envelope. If your application receives JSON responses from a REST API but needs to forward data to a SOAP-based service — common in banking, insurance, and government systems — you must convert that JSON payload to well-formed XML before sending it. The converter generates the core XML payload; you then wrap it in the SOAP envelope structure (<soapenv:Envelope>, <soapenv:Body>) required by the target WSDL definition.


Enterprise System Integration — SAP, MuleSoft, Oracle

Enterprise middleware platforms process enormous volumes of structured data and predominantly use XML as their interchange format. SAP IDOC (Intermediate Document) files, MuleSoft Anypoint Platform message flows, and Oracle Service Bus (OSB 12c) routing rules all consume XML natively. When a modern microservice outputs JSON, it must be converted before it enters these systems. For Oracle SOA 12c and IBM Integration Bus environments, the same applies — XML is the standard message format for service orchestration layers.


Healthcare Data — HL7 and FHIR

HL7 FHIR R4 (Fast Healthcare Interoperability Resources) supports both JSON and XML serialization formats. However, many older Electronic Health Record (EHR) systems — Epic, Cerner legacy modules, and various regional health information exchanges — only accept HL7 XML. Clinical data exported from modern APIs in JSON must be converted before submission to these systems. The conversion must preserve element ordering and data types precisely, as HL7 XML schemas have strict validation rules.


RSS and Atom Feed Generation

RSS 2.0 and Atom 1.0 feeds are XML documents. If your content management system or API stores article metadata in JSON (headline, publish date, author, URL), you need to convert that data to XML before generating a valid RSS feed for syndication. This is a common requirement for headless CMS setups and news aggregation pipelines.


Data Migration and ETL Pipelines

Enterprise ETL (Extract, Transform, Load) tools — Informatica PowerCenter, Talend, IBM DataStage, and MuleSoft — frequently require XML as the staging format between source extraction and target loading. Data originally stored in JSON (MongoDB exports, API snapshots, configuration files) must be converted before entering these pipelines. Batch conversion is especially useful here, allowing you to process entire folders of JSON export files at once.


Configuration Files and Legacy Applications

Many legacy Java applications, Android projects, and older .NET frameworks use XML for configuration (web.config, applicationContext.xml, pom.xml). If you're migrating configuration data from a modern JSON format back to XML, this converter handles the structural translation cleanly.


JSON vs XML — Key Differences at a Glance

Feature JSON XML
Syntax Key-value pairs, curly braces, square brackets Opening/closing tags, hierarchical
Data types String, number, boolean, null, object, array Everything is text; types via XSD
Attributes Not supported natively First-class feature (id="123")
Namespaces Not supported Full namespace support (xmlns)
Schema validation JSON Schema XSD (XML Schema Definition)
File size Smaller (less markup) Larger (opening + closing tags)
Best for REST APIs, web apps, mobile SOAP, enterprise systems, HL7, config

Key Features of the AllFileTools JSON to XML Converter

  • Paste or upload — paste raw JSON text directly, or upload a .json or .txt file from your device
  • Batch conversion — upload multiple JSON files at once and download all results as a single ZIP archive
  • XML attribute support — use the @ prefix convention to generate real XML attributes, not just nested elements
  • Pretty-print output — the converted XML is automatically indented and formatted for readability
  • Syntax highlighting — powered by CodeMirror, the editor highlights both JSON input and XML output
  • No file storage — your files are permanently deleted within one hour of conversion; nothing is retained or analyzed
  • Special character escaping — XML-reserved characters (<, >, &, ", ') in JSON values are automatically escaped to valid XML entities

How JSON to XML Conversion Works — Technical Overview

The converter processes your JSON recursively. It starts at the root of the JSON structure and maps every key to an XML element name. If the value is a primitive (string, number, boolean, null), it becomes that element's text content. If the value is an object, the converter recurses into it, creating nested child elements. If the value is an array, it iterates through each item, creating repeated elements of the same name for object items, or <item> elements for primitives.

The output conforms to the W3C XML 1.0 specification. An <?xml version="1.0" encoding="UTF-8"?> declaration is prepended, and a <root> element is added automatically when the JSON root is an object without a single top-level key, ensuring the output is always well-formed XML.


How to Convert JSON Array to XML Array

A JSON array like "employees": [...] produces repeated <employees> elements — one for each array item. This is the standard XML convention for list data, equivalent to how RSS items work (<item> repeating inside a <channel>). If you need a wrapper element around the repeating elements, structure your JSON with an extra nesting level: { "employees": { "employee": [...] } }.


How JSON Keys Map to XML Element Names

XML element names must follow strict rules per the W3C XML 1.0 specification: they cannot start with a number, cannot contain spaces, and cannot include characters like !, @ (except for the attribute prefix convention), #, or $. If your JSON contains keys that violate these rules — for example, "1stItem" or "my key" — the converter sanitizes them automatically by prefixing numeric-starting keys with an underscore (_1stItem) and replacing spaces with hyphens (my-key). The original value is preserved; only the element name is adjusted.


Common JSON to XML Conversion Errors — and How to Fix Them

Invalid JSON Syntax

Symptom: The converter returns an error message and produces no XML output.

Most common causes:

  • Trailing comma after the last key-value pair: { "name": "Alice", } — valid in JavaScript but not in strict JSON
  • Single quotes instead of double quotes: { 'name': 'Alice' } — JSON requires double quotes
  • Missing closing bracket — an unclosed { or [ somewhere in the structure

Fix: Run your JSON through the AllFileTools JSON Formatter & Validator first. It highlights the exact line and character where the syntax error occurs. Fix the error there, then return here for conversion.


Invalid XML Element Name

Symptom: Conversion succeeds but the XML output contains sanitized or unexpected element names.

Cause: A JSON key that starts with a number (e.g., "2024_report") or contains a space (e.g., "first name") is not a valid XML element name.

Fix: Rename the JSON key before converting. Use underscore-separated or camelCase naming: "report_2024" or "firstName". If you cannot change the source JSON, the converter's auto-sanitization will handle it, but document the name change so downstream systems know what to expect.


Root Element Error with Top-Level JSON Arrays

Symptom: You paste a JSON array ([{...}, {...}]) and the output has an unexpected <root> or <item> wrapper.

Cause: XML requires a single root element. A top-level JSON array has no natural root — so the converter wraps it in <root><item>...</item></root> automatically.

Fix: Wrap your JSON in an object before converting: { "records": [{...}, {...}] }. This gives the converter a meaningful root element name (<records>) instead of the generic <root>.


Convert JSON to XML Programmatically

For developers who need to automate the conversion as part of a pipeline or application, here are working code snippets in the most common languages. For one-off conversions during development and testing, the online tool above is significantly faster than writing and running code.


How to Convert JSON to XML in Python

Use the dicttoxml library for straightforward Python JSON to XML conversion:

python

import json
import dicttoxml

# Install: pip install dicttoxml

with open("data.json", "r") as f:
    json_data = json.load(f)

xml_output = dicttoxml.dicttoxml(json_data, custom_root="root", attr_type=False)
print(xml_output.decode("utf-8"))

The attr_type=False parameter suppresses automatic type attributes on elements (e.g., type="str"), producing cleaner output. For fine-grained control over element naming and attribute handling, use the xml.etree.ElementTree module from the standard library instead.

How to Convert JSON File to XML in Python / How to Convert JSON Object to XML File in Python

python

import json, dicttoxml
from xml.dom.minidom import parseString

with open("input.json") as f:
    data = json.load(f)

xml_bytes = dicttoxml.dicttoxml(data, custom_root="root", attr_type=False)
pretty_xml = parseString(xml_bytes).toprettyxml(indent="  ")

with open("output.xml", "w") as out:
    out.write(pretty_xml)

How to Convert JSON to XML in JavaScript / Node.js and XML to JSON in Node.js

JSON to XML in Node.js using the xml-js library:

javascript

// npm install xml-js
const convert = require("xml-js");
const fs = require("fs");

const jsonData = fs.readFileSync("data.json", "utf8");

const xmlOutput = convert.json2xml(jsonData, {
  compact: true,
  spaces: 2,
  declaration: { attributes: { version: "1.0", encoding: "UTF-8" } }
});

fs.writeFileSync("output.xml", xmlOutput);
console.log("Conversion complete.");

How to Convert JSON to XML Using Java

Java's org.json library includes a built-in XML.toString() method for direct JSON-to-XML conversion:

java

import org.json.JSONObject;
import org.json.XML;

// Maven: org.json:json:20240303

public class JsonToXml {
    public static void main(String[] args) {
        String jsonString = "{\"name\":\"Alice\",\"age\":30,\"city\":\"Berlin\"}";
        JSONObject jsonObject = new JSONObject(jsonString);
        String xmlOutput = XML.toString(jsonObject, "root");
        System.out.println(xmlOutput);
    }
}

Output: <root><name>Alice</name><age>30</age><city>Berlin</city></root>

How to Convert JSON to XML in Java Spring Boot

In Spring Boot, use the Jackson XmlMapper with ObjectMapper:

java

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.databind.ObjectMapper;

ObjectMapper jsonMapper = new ObjectMapper();
XmlMapper xmlMapper = new XmlMapper();

// JSON string → XML
Object jsonObject = jsonMapper.readValue(jsonString, Object.class);
String xmlOutput = xmlMapper.writeValueAsString(jsonObject);

// XML string → JSON
Object xmlParsed = xmlMapper.readValue(xmlString, Object.class);
String jsonOutput = jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(xmlParsed);

Dependency: com.fasterxml.jackson.dataformat:jackson-dataformat-xml

How to Convert XML to JSON in Java Using Jackson

java

XmlMapper xmlMapper = new XmlMapper();
ObjectMapper jsonMapper = new ObjectMapper();
JsonNode node = xmlMapper.readTree(xmlString.getBytes());
String json = jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(node);

Privacy and Security

All JSON data you paste or upload is processed entirely within your browser session and permanently deleted from our servers within one hour. Your data is never shared, analyzed, or retained. All connections use HTTPS encryption. See our Privacy Policy for full details.


Frequently Asked Questions

How to Convert JSON to XML Using Allfiletools

Paste your JSON into the input box at the top of this page and click Convert. The tool validates your JSON, maps each key to an XML element, and produces download-ready XML in seconds. For programmatic conversion, see the Python, JavaScript, Java, and C# code examples on this page.

What happens to JSON arrays during XML conversion?

Each item in a JSON array becomes a repeated XML element with the same tag name. For example, a "users" array containing three objects produces three <user> child elements under a <users> parent. If the top-level JSON value is itself an array (not an object), the converter wraps the output in a <root> element to ensure the XML is well-formed.

Is my JSON data stored on your servers?

No. Files are automatically and permanently deleted within 1 hour of conversion. We do not log file content, store conversion history, or share your data with any third party. All transfers use HTTPS encryption.

How to convert XML to JSON

Use the AllFileTools XML to JSON Converter — it works in the same way: paste your XML or upload a .xml file and get clean JSON output. For programmatic XML-to-JSON conversion, see the Python (xmltodict), JavaScript (xml-js), and Java (org.json XML.toJSONObject) code examples on this page.


Can I convert JSON to XML with XML attributes?

Yes. Prefix any JSON key with @ to generate an XML attribute on the parent element. For example, {"user": {"@id": "123", "name": "Alice"}} produces <user id="123"><name>Alice</name></user>. See Example 4 above for a full walkthrough. This is the most important feature for SOAP API and enterprise system integration.

How to Convert JSON to XML in JavaScript

In Node.js, use the xml-js library: convert.json2xml(jsonString, { compact: true, spaces: 2 }). For browser-side conversion without a library, see the vanilla JavaScript function in the JavaScript section above. Full code with require() statements and file I/O is in the JavaScript section.


How to Convert JSON to XML in C#

Use Newtonsoft.Json: JsonConvert.DeserializeXmlNode(jsonString, "root").OuterXml. Install via NuGet: Newtonsoft.Json. Full examples including XML-to-JSON reversal are in the C# section above.


Why is my JSON to XML conversion failing?

The three most common causes: (1) Invalid JSON syntax — trailing commas and single quotes are the most frequent culprits. Validate your JSON first using the JSON Formatter. (2) A top-level JSON array with no root object wrapper — XML requires a single root element. Wrap the array: { "items": [...] }. (3) JSON keys that start with numbers or contain special characters — the converter sanitizes these automatically, but check the output if element names look unexpected.


How to Convert JSON to XML Using PHP

Use PHP's SimpleXMLElement class. See the complete recursive jsonToXml() function in the PHP section above. No third-party library is required. For file-to-file conversion, use file_get_contents() for input and $xml->asXML('output.xml') for output.