HomeJSON ToolsJSON to XML Converter

JSON to XML Converter

Convert any JSON object to well-formed XML instantly. Maps JSON objects to XML elements, arrays to repeating elements, and produces properly indented, valid XML with a configurable root element — ready for SOAP integrations, legacy system APIs, XML-based configuration formats, and any system that requires XML over JSON.

Convert any JSON object to well-formed XML instantly. Maps JSON objects to XML elements, arrays to repeating elements, and produces properly indented, valid XML with a configurable root element — ready for SOAP integrations, legacy system APIs, XML-based configuration formats, and any system that requires XML over JSON.

This tool is designed to provide a seamless experience for developers by handling complex operations directly in your browser with maximum speed and security.

100% Private
Instant Results
Customizable
Offline Ready
Dev-Friendly
Easy Export

JSON and XML are both text-based formats for representing structured data, but they come from different eras and have different strengths. JSON was designed for simplicity and JavaScript interoperability — compact, easy to parse, native to web browsers. XML was designed for enterprise data exchange and document markup — verbose but precise, with a rich ecosystem of standards for schema validation (XSD), transformation (XSLT), querying (XPath/XQuery), and namespaces for avoiding naming conflicts between schemas from different organizations. The JSON-to-XML conversion challenge is that the two models are not perfectly equivalent: XML has attributes in addition to elements (a distinction JSON does not have), XML can have mixed content (text and child elements interleaved), and XML requires a single root element whereas a JSON array at the top level has no natural root.

XML is not going away. It is the foundation of SOAP web services, which remain widespread in financial services, healthcare, government systems, and enterprise software. A REST API that returns JSON may need to call a backend SOAP service that expects XML in the request body. Spring-WS, Apache CXF, JAX-WS, and .NET's WCF are all SOAP frameworks still in active use in enterprise environments. Android's layout system is XML. Maven pom.xml and build.gradle (in its XML form) are XML. Microsoft Office document formats (docx, xlsx) are ZIP archives of XML files. RSS and Atom feeds are XML. SVG is XML. The Android, Java enterprise, and .NET ecosystems all have deep XML roots that are not being retired any time soon.

JSON to XML conversion is the process of mapping the JSON data model to the XML element hierarchy. A JSON object with properties becomes an XML element with child elements for each property. A JSON array becomes a sequence of sibling XML elements with the same tag name. A JSON string, number, or boolean becomes an XML element's text content. JSON null has no clean XML equivalent and is typically represented as an empty element or omitted. The converted XML can be used directly as the body of a SOAP request, as input to an XSLT transformation, as configuration for a system that reads XML, or as the payload for a legacy API that predates REST and JSON.

Paste a JSON object or array and click Generate XML Data. The tool wraps the converted content in a root element (defaulting to root — you can customize this), maps each JSON object property to a child element with the property name as the tag, maps JSON arrays to sequences of sibling elements with the same tag derived from the parent key, converts JSON primitives (strings, numbers, booleans) to XML text content inside their respective elements, and renders null as an empty self-closing element. The output is pretty-printed with 2-space indentation and includes an XML declaration header (). Array handling is worth understanding specifically. When a JSON object has a key with an array value — {"roles": ["admin", "user"]} — the tool generates sibling role elements: role admin/role followed by role user/role. The singular form of the array key is used as the element name for each item. For arrays of objects — {"items": [{"id": 1}, {"id": 2}]} — the tool generates item elements containing the nested object's properties as child elements. The element name used for array items comes from the parent key, which is usually correct, but if the target XML schema uses a different element name for array items, you will need to edit the output accordingly. The JSON Schema button on the tool lets you view a JSON Schema representation of the input data alongside the XML output. This is useful when you need to document the structure or generate a matching XSD schema for the converted XML. The generated XML is well-formed but not schema-validated — if your SOAP endpoint or legacy system requires XML that conforms to a specific XSD schema, the converted XML is a starting point that may need additional XML attributes, namespace declarations, or structural adjustments to match the exact schema the system expects.

1. Paste your JSON into the Input JSON field — use a JSON object (starting with {) that represents the data structure you want to convert. If your JSON is an array at the top level, the array items will be converted to sibling elements inside the root wrapper. Click Load Example to see the conversion behavior with a nested object before using your own data.

2. Click Generate XML Data — the tool wraps your JSON in a root element, maps each property to a child XML element, converts nested objects to nested element hierarchies, converts arrays to sequences of sibling elements, maps primitive values to element text content, and outputs the well-formed XML with consistent 2-space indentation.

3. Review the root element name — the default root element is root. If your target XML schema or SOAP service expects a specific root element name (like Request, Envelope, or the actual entity name like User or Product), edit the root tag name in the output directly before copying. For SOAP specifically, the root element and envelope structure are defined by the WSDL — the converted XML from your data goes inside the Body element of the SOAP envelope.

4. Check array element names — JSON array items are converted to elements named from the singular form of the parent key (a roles array generates role elements). If the target schema uses different element names, adjust them in the output. If the schema uses repeating elements with the same name as the array key (roles instead of role), update those tag names before using the XML.

5. Copy the XML output and use it in your target system — paste it as the body of a SOAP request in SoapUI or Postman, use it as input to an XSLT transformation, save it as an XML configuration file, or use it as the starting point for a JAXB or DOM-based XML construction in your application code.

The scenario where JSON-to-XML conversion comes up most in backend work is bridging a modern REST API to a legacy SOAP service. Your new Node.js or Python service talks in JSON — your payment processor, your HR system, or your enterprise ERP from 2005 talks in SOAP XML. The middleware layer needs to translate. When you are building that middleware and trying to understand what XML structure the SOAP service expects, generating the XML from a JSON data object and comparing it to the WSDL schema is the fastest way to check your mapping logic before writing the production transformation code. This tool is that quick check. Maven pom.xml editing is another consistent XML need for Java developers. A Maven multi-module project configuration that starts as a data structure — module names, dependency versions, build profiles — is easier to compose as JSON and then convert to the XML format that Maven expects. The same applies to Ant build files, Spring XML configuration (though Spring Boot has mostly replaced this with properties files and annotations), and TestNG XML suite configurations. None of these are pure data — they have specific XML structures the tool must conform to — but the JSON-to-XML conversion gives you the structural scaffold and the element hierarchy from which you adjust the specific tag names and add required XML attributes. There is also the debugging and exploration context. When you are integrating with a legacy system that only accepts XML and the documentation is poor, converting a sample JSON request to XML and comparing the element structure to the error messages the system returns is a faster path to understanding what the system expects than reading XML schema documentation. The converted XML shows you the hierarchy; the system's error messages tell you what is wrong with that hierarchy. This iterative approach — convert, send, read error, adjust — is often faster than reading the XSD thoroughly first.

Correct element nesting — JSON object hierarchy is faithfully represented as nested XML elements with each level indented 2 spaces matching the XML convention

Array to repeating elements — JSON arrays generate sibling XML elements with the same tag name derived from the parent key giving you correct repeating element structure rather than a single concatenated value

XML declaration included — the output includes the standard XML declaration header (xml version 1.0 encoding UTF-8) making the output valid as a standalone XML document

Pretty-printed output — consistent 2-space indentation makes the XML readable and suitable for documentation SOAP testing tools and configuration files

JSON Schema button — shows a JSON Schema representation of the input alongside the XML output for structure documentation

100% browser-based — your JSON data never leaves your machine which matters when the data includes internal API payloads user records or sensitive configuration values

Well-formed XML output — the generated XML passes well-formedness validation and can be parsed by any standards-compliant XML parser

Instant generation — parsing and conversion runs locally in your browser with results appearing immediately for any size input

Generating XML request payloads for SOAP web service integrations from JSON data structures

Converting REST API JSON responses to XML format for consumption by legacy enterprise systems that do not accept JSON

Building XML configuration files for Java-based tools like Maven TestNG or Ant from JSON data objects

Creating XML data fixtures for testing XML-based parsing or transformation code

Converting JSON data exports to XML for import into systems that only accept XML such as some ERP and CRM platforms

Generating XML from JSON as a starting point for constructing JAXB object models or DOM-based XML builders

Debugging legacy XML API integrations by rapidly generating XML from JSON to understand element naming and nesting expectations

Transforming JSON API responses to XML for feeds or integrations that require RSS Atom or other XML-based formats

Example Input

{
  "user": {
    "id": 1,
    "name": "Priya Singh",
    "email": "priya@learnhubly.com",
    "roles": ["admin", "developer"],
    "profile": {
      "bio": "Principal Software Engineer"
    }
  }
}

Example Output


<root>
  <user>
    <id>1</id>
    <name>Priya Singh</name>
    <email>priya@learnhubly.com</email>
    <roles>
      <role>admin</role>
      <role>developer</role>
    </roles>
    <profile>
      <bio>Principal Software Engineer</bio>
    </profile>
  </user>
</root>

Invalid JSON Input: The tool requires valid JSON before converting to XML. Common issues: missing commas between properties, unquoted keys, trailing commas, or single-quoted strings. JSON requires double quotes for all strings including keys. Use the JSON Formatter and Validator tool to fix any syntax errors first, then retry the conversion.

Root Element Missing — JSON Must Have a Single Root Object: XML requires exactly one root element that contains all other elements. JSON arrays at the top level (starting with [) do not have a natural single root. The tool wraps top-level arrays in a root element — but if your target XML schema requires a specific element name for the array wrapper, edit the root tag name after conversion. If the conversion produces multiple top-level elements that look wrong, verify that your JSON has a single top-level object rather than multiple top-level keys without a wrapper.

Array Element Names Using Wrong Form: The tool converts array item element names from the parent array key using singularization — a roles array generates role elements, an items array generates item elements. If the target XML schema uses the plural form for array items (roles elements instead of role) or uses a completely different element name, you must edit the element names in the generated XML before using it. XML element naming in schemas is domain-specific and the tool can only guess based on the JSON key name.

JSON Keys That Are Not Valid XML Element Names: XML element names cannot start with a number, cannot contain spaces, and cannot contain characters like & < > ' " / that have special meaning in XML. A JSON key like 1st-name, my field, or x&y would produce an invalid XML element name. If your JSON has keys that violate XML naming rules, the tool may produce invalid XML or escape the names in a way that does not match the target schema's expected element names. Rename problematic JSON keys before converting.

Null Values Producing Empty Elements That Fail Schema Validation: JSON null values are converted to empty self-closing elements in the output. An XML element like deletedAt/ (empty) may not match what a target XSD schema expects for a null value. Some XML schemas represent null with an xsi:nil='true' attribute on the element, others expect the element to be absent entirely. If a null field in your JSON causes validation failures in the target XML system, either remove null fields from the JSON before converting or add the appropriate xsi:nil attribute or absence handling manually in the XML output.

Using the converted XML directly as a SOAP request body without adding the SOAP envelope

Fix: SOAP messages have a mandatory structure: an Envelope element containing a Header (optional) and a Body element. Your actual request data goes inside the Body element. The XML this tool generates is the payload content — it needs to be wrapped in the SOAP envelope before it can be sent to a SOAP endpoint. The minimal SOAP 1.1 envelope looks like: soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' / soapenv:Body / [your converted XML here] /soapenv:Body /soapenv:Envelope. SOAP 1.2 uses a different namespace. Add the target SOAP namespace declarations from the WSDL, wrap the converted XML in the correct envelope, and validate against the WSDL before sending.

Expecting JSON attributes to map to XML attributes

Fix: JSON does not have a concept of attributes — everything in JSON is either a property of an object or an element of an array. XML has two distinct concepts: elements (the tags) and attributes (key-value pairs inside the opening tag). The converter maps all JSON properties to XML child elements, not XML attributes. If the target XML schema expects an element to have attributes — like user id='1' name='Priya' rather than user / id 1 /id / name Priya /name /user — you must manually edit the converted XML to move the appropriate properties to attributes, or use a custom XML construction approach in code where you have explicit control over element vs attribute mapping.

Not adding XML namespace declarations required by the target schema

Fix: Many enterprise XML schemas and all SOAP messages use XML namespaces to qualify element and attribute names: xmlns:usr='http://example.com/user' and then usr:User instead of plain User. The converter produces plain XML without namespace declarations. If your target system requires namespace-qualified elements, add the xmlns declarations to the root element of the converted XML and prefix the element names that the schema requires. In SOAP specifically, the envelope namespace (soapenv:) and the service-specific namespace (tns:) from the WSDL both need to be declared and applied to the correct elements.

Treating JSON to XML as a lossless round-trip format

Fix: Converting JSON to XML and then XML to JSON does not reliably return the original JSON. The conversions are not inverses. JSON arrays become repeating XML elements — when those elements are converted back to JSON, the tool has to infer that repeating elements should be an array, which it may or may not do correctly. JSON null becomes an empty XML element — empty XML elements often convert back to empty strings in JSON, not null. XML attributes have no JSON equivalent. For data that needs to travel through both formats and back, define explicit mapping rules for each direction rather than relying on automatic round-trip conversion.

Converting the entire JSON response payload to XML when only part of it needs to be in XML

Fix: When bridging a REST API to a SOAP service, you typically need to transform only the data fields into XML for the SOAP request body — not the entire API response including pagination metadata, status codes, or other response envelope fields that have no equivalent in the SOAP request. Extract the relevant data from the full JSON response first, construct the minimal JSON structure that maps to the SOAP request body structure, then convert that subset to XML. Converting the entire raw JSON response to XML and hoping it matches the SOAP schema wastes time and produces XML that does not match the expected SOAP message structure.

Does it handle arrays?

Yes. JSON arrays are converted to sequences of sibling XML elements. A roles array containing ['admin', 'user'] becomes two role elements (using the singular of 'roles') inside a roles wrapper element. An array of objects becomes sibling elements, each containing the object's properties as child elements. The element name for array items is derived from the parent key — roles becomes role elements, items becomes item elements. If the target schema uses different element names for array items, edit the generated element tags before using the XML.

Can I customize the root tag?

The tool uses root as the default root element name. To change it, edit the opening and closing root tags in the generated XML output directly — replace root with your intended element name like Request, Response, User, or whatever the target schema expects. For SOAP, the generated XML does not go inside a root element at all — it goes inside the soapenv:Body element of the SOAP envelope, so remove the root wrapper and add the SOAP envelope structure around the converted content.

Is it safe for internal API payloads?

Yes. All conversion runs in your browser using JavaScript. Your JSON content — including any internal data model fields, sensitive values, or proprietary payload structures — never leaves your machine. This is relevant for enterprise integration work where the JSON you are converting may contain internal service URLs, authentication tokens, or other information you would not want transmitted to a third-party tool.

What is the difference between converting JSON to XML vs writing XML directly?

For complex schemas with namespace requirements, XML attributes, mixed content, and processing instructions, writing XML directly in a code editor with schema validation gives you more control and catches errors immediately. JSON-to-XML conversion is the right approach for exploratory work — quickly generating a plausible XML structure from a data object to understand the element hierarchy, compare to a schema, or generate a test fixture. For production code that constructs XML programmatically, use a proper XML library: JAXB in Java, lxml in Python, DOMDocument in PHP, the xml package in Go — these give you explicit control over attributes, namespaces, and schema compliance.

How do I convert JSON to XML in code?

In JavaScript (Node.js): use the xml2js package — const builder = new xml2js.Builder(); const xml = builder.buildObject(jsonObject). In Python: use the dicttoxml package — import dicttoxml; xml = dicttoxml.dicttoxml(json_dict, root=True). In Java: use JAXB — annotate a Java class with @XmlRootElement and @XmlElement, populate it from JSON, and use JAXBContext.newInstance(User.class).createMarshaller().marshal(user, System.out). In .NET: use Newtonsoft.Json — XDocument doc = JsonConvert.DeserializeXNode(jsonString, 'root'). Each library has different rules for attribute vs element mapping and array handling, so test with a sample before using in production.

Why does the XML for a SOAP service look different from the JSON I convert?

SOAP XML has structural requirements that the JSON data does not: the SOAP envelope with its soapenv: namespace prefix, the Body element, service-specific namespace declarations from the WSDL, and the exact element names and nesting that the service endpoint expects. Converting your data JSON to XML gives you the data structure in XML form, but the SOAP message structure is a wrapper around that data, not derived from it. Read the WSDL's message definitions and operation schemas to understand the exact XML structure the endpoint expects, use this tool to generate the data portion, then manually construct the SOAP envelope around it, or use a SOAP client library that handles the envelope construction automatically.

Does JSON have an equivalent to XML attributes?

No. XML has two ways to attach information to an element: child elements (content between the opening and closing tags) and attributes (key-value pairs in the opening tag). JSON has only one mechanism: object properties. When converting JSON to XML, all JSON properties become child elements — there is no automatic mapping to XML attributes because JSON has no concept of attributes. If you need XML attributes in the output (common in SOAP and many XML schemas), you must add them manually after the conversion or use a conversion library that has explicit rules for which JSON properties become attributes and which become elements — json2xml in Python has an attr_type option, and xml2js in Node.js has the headless and explicitArray options.

Can I convert XML back to JSON?

Yes — use the XML to JSON or the JSON Formatter tool on LearnHubly which handles XML input. Note that XML-to-JSON conversion is not a perfect inverse of JSON-to-XML — XML attributes become nested objects with a dollar-sign key convention in most libraries, XML text content mixed with child elements requires special handling, and XML namespaces have no natural JSON equivalent. For data that round-trips through both formats, it is better to define explicit transformation rules for each direction rather than relying on automatic conversion in both directions.