🔁

JSON to XML

✓ Free & no signup 🔒 Runs 100% in your browser Updated 2026-11-25 Development Tools

Your backend speaks JSON; the system you just integrated with — a payment partner, a legacy ERP, a government submission portal — wants XML, and it wants it in a specific shape with a specific root element. This converter transforms JSON into well-formed XML with the structure rules made explicit: you choose the root element name, arrays become repeated elements, and bare scalar values get a predictable wrapper. Parsing and generation both happen in your browser, so payloads with order details or customer data stay local.

The reason structure rules matter: JSON and XML do not map one-to-one. XML has exactly one root element; JSON allows a bare number, string, or array at the top level. XML has attributes and text content; JSON has only keys and values. A converter that stays silent about those mismatches produces XML with a root named root and no explanation, and you discover the mismatch in a partner's validation error hours later. Here, the choices are yours and they are visible.

The Transformation Rules

Four rules govern the output, and every one of them shows up in real integrations:

  • Objects become elements. Each key becomes a child element name. {"city": "Denver", "zip": "80202"} becomes <city>Denver</city><zip>80202</zip> inside the parent.
  • Arrays repeat elements. An array of three objects produces three sibling elements with the same name — the natural XML idiom for lists. {"sku": ["A-1", "A-2"]} yields <sku>A-1</sku><sku>A-2</sku>.
  • Scalars at the top level get a wrapper. JSON permits a bare 42 or "hello" as a whole document; XML does not, so the value lands inside the configurable root element, producing <root>42</root> rather than refusing the job.
  • The root element is configurable. You name the outermost element to match what the receiving system's schema demands, whether that is order, invoiceRequest, or a partner-specified name with a namespace.

A worked example ties the rules together. This JSON shipment record:

  • { "shipment": { "id": "S-3091", "weight_kg": 12.5, "boxes": [ { "code": "B1", "count": 4 }, { "code": "B2", "count": 2 } ] } }

becomes XML with a shipment element containing id and weight_kg children, and two repeated boxes elements — each a boxes element wrapping its own code and count. The array did not become an XML attribute or a comma-joined string; it became the repeated-element structure that XML schemas and XPath were designed around, which is exactly what the receiving side's parser expects.

How to Use It (Step by Step)

  1. Paste your JSON into the input area. Invalid JSON is reported with its error position before any conversion runs, so a broken input never produces half-transformed output.
  2. Set the root element name to whatever the receiving schema requires; the default is a neutral generic name you can change in one field.
  3. Convert, and read the generated XML — well-formed, indented, and structurally faithful to your objects and arrays.
  4. Copy the result or download it as an .xml file for submission to the partner system or for dropping into your build.
  5. When the receiving system rejects the payload, compare element names against its schema first; most rejections are naming mismatches, not structural ones.

API Response Transformation: The Real Workflow

The most common scenario is a bridge. You operate a JSON API, and a partner's system consumes XML through an older integration layer — SOAP-era middleware, an EDI gateway, a procurement platform pinned to a 2012 schema. Hand-writing the transformation for every field is error-prone; this converter handles the mechanical part, and you review the shape. Because arrays become repeated elements and objects nest faithfully, the output matches the mental model a schema designer had: a list of line items in an order is naturally <lineItems> repeated under <order>, not a JSON string smuggled inside one element.

Straight-through processing pipelines use the same move in the other direction of trust: generate the XML once, validate it against the partner's XSD, and pin the transformation as a fixture in your tests. If the partner ever changes the schema, the fixture breaks loudly in CI rather than quietly in production at 2 a.m. The converter's role in that pipeline is producing a deterministic baseline — same JSON in, same XML out, every time, with no server round-trip to introduce variance.

JSON and XML: Two Structurally Different Worlds

Knowing where the formats genuinely differ helps you predict what the receiving system can and cannot express. The table below maps the concepts:

JSON conceptXML counterpartWhat to watch for
ObjectElement with child elementsDirect mapping, no surprises
ArrayRepeated sibling elementsConsumer must expect the same name repeated
Number, booleanText contentXML sees characters; schema types live in the XSD
nullEmpty elementSome schemas reject empty elements — check required fields
Top-level scalarWrapped in the root elementThe wrapper is the converter's, not yours

One honest limitation to plan around: JSON keys with characters illegal in XML element names — starting with a digit, containing spaces or hyphens in awkward positions — cannot become element names as-is, so keys like "2fa_enabled" need renaming upstream if your source data contains them. Clean keys convert cleanly; messy keys deserve a pre-pass.

Tips and Best Practices

  • Name your root element after the document, not the transport: invoice, not request — schema validators and human reviewers both benefit.
  • Check how the consumer expects lists: repeated elements are the XML-native idiom, but a few legacy schemas want wrapper elements around each item; confirm before generating hundreds of payloads.
  • Convert types at the boundary in your JSON first — a price of 12.50 serializes as text in XML either way, so make sure the string form is the one you want to send.
  • Keep nulls out of required fields; an empty element is rarely what a partner schema means by present.
  • Round-trip sanity check: push the generated XML back through an XML-to-JSON converter and diff the structures to catch accidental nesting mistakes.

Frequently Asked Questions

How do JSON arrays become XML elements?
Each array item becomes a repeated element with the same name under the parent, which is the standard XML idiom for lists. An array of three product objects produces three sibling product elements, each containing its own child elements. This matters for integration work because XML schemas and XPath expect repeated elements rather than comma-joined strings or attributes, so the output drops into partner systems without reshaping. If a consumer expects wrapper elements around each item instead, confirm its schema before generating the payloads.
Why does my JSON need a root element for XML?
XML requires exactly one root element wrapping the entire document, while JSON allows anything — an object, an array, even a bare number — at the top level. The converter therefore wraps your data in a root element whose name you control, so you can match what the receiving schema demands, such as order, invoiceRequest, or a partner-specified name. The configurable name is more than cosmetics: many validation failures between systems trace back to a root element mismatch, and setting it here avoids a rejected submission and a resubmission cycle.
What happens to numbers and booleans in JSON-to-XML conversion?
They become text content, because XML has no native number or boolean types — types live in the schema that validates the document, not in the document itself. A JSON value of 12.5 serializes as the characters 12.5, and true becomes the string true. Most receiving systems parse these back correctly when their schema declares the element as a decimal or boolean type. The one habit worth adopting: check how your source formats numbers, since a JavaScript float can serialize as 12.499999 where your partner expects 12.5 — round before converting.
Can every JSON document be converted to XML?
Almost every, with honest caveats. Objects, arrays, strings, numbers, booleans, and null all map to XML structures. The genuine blockers are keys that are illegal as XML element names — names starting with a digit or containing spaces or characters XML forbids — since those cannot become elements without renaming. Null values convert to empty elements, which some schemas reject for required fields. If your source keys are messy, clean them upstream first; the converter transforms structure faithfully but cannot invent legal element names out of illegal ones.
How do I convert a JSON API response into XML for a legacy system?
Paste the response into the converter, set the root element name to match the legacy schema, and generate. Arrays become repeated elements and objects nest faithfully, so a typical response maps naturally: an order object becomes an order element with child elements for each field and repeated line-item elements for arrays. Validate the output against the partner's schema, then pin a converted example as a test fixture so schema changes break your build rather than production. The conversion runs locally, so live customer payloads never leave your machine.
Is the generated XML valid and well-formed?
Well-formed, always: every element is properly closed, nesting is consistent, and there is exactly one root, which is what well-formed means technically. Valid is a separate question — validity means conforming to a specific schema such as an XSD that defines allowed element names, ordering, and types, and only the receiving system's schema can answer that. Practical advice: generate the XML here, run it through the partner's validator once, and record the exact root name and structure they accept. After that, every future conversion reproduces the same accepted shape.

Related Tools