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
42or"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)
- 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.
- Set the root element name to whatever the receiving schema requires; the default is a neutral generic name you can change in one field.
- Convert, and read the generated XML — well-formed, indented, and structurally faithful to your objects and arrays.
- Copy the result or download it as an .xml file for submission to the partner system or for dropping into your build.
- 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 concept | XML counterpart | What to watch for |
|---|---|---|
| Object | Element with child elements | Direct mapping, no surprises |
| Array | Repeated sibling elements | Consumer must expect the same name repeated |
| Number, boolean | Text content | XML sees characters; schema types live in the XSD |
| null | Empty element | Some schemas reject empty elements — check required fields |
| Top-level scalar | Wrapped in the root element | The 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, notrequest— 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.50serializes 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.