DevKits

JSON to XML Converter — Online, Free, No Upload

Convert JSON to XML online. Attributes via @-prefixed keys, #text for element content, automatic array-to-repeated-siblings expansion. Emits a valid XML declaration. 100% local.

Last updated:

360 chars · 20 lines

Paste JSON on the left to get valid, indented XML with attributes hoisted from @-prefixed keys and repeated siblings expanded from arrays. Emits a proper <?xml ?> declaration. All local in your browser.

What is JSON → XML?

A JSON to XML converter goes the other direction of the more common XML → JSON flow: taking a modern JSON structure and emitting a well-formed XML document that legacy APIs and enterprise systems can consume. The main design challenge is that XML has attributes and JSON doesn't — this tool uses the standard convention of treating keys prefixed with @ as attributes and a #text key as element content. Arrays automatically expand into repeated sibling elements sharing the same tag, matching how fast-xml-parser and xml2js round-trip data. Element and attribute names are validated against XML 1.0 naming rules, and reserved characters (&, <, >, ", ') are escaped correctly in both element text and attribute values.

How to convert JSON to XML online

  1. 1Paste your JSON into the left editor. Wrap it in a single-key object like { "library": { ... } } if you want a specific root element.
  2. 2The right pane instantly renders the XML equivalent with matching indentation.
  3. 3Prefix attribute keys with @ (or $ / _ — switchable in the toolbar) so they become XML attributes rather than child elements.
  4. 4Toggle the <?xml version="1.0" encoding="UTF-8"?> declaration and override the root element name in the toolbar as needed.
  5. 5Copy the XML output — it's already validated for well-formedness.

Use Cases

Feed legacy XML APIs

Some enterprise, government, and financial systems only accept XML. Prepare payloads in JSON (which is easier to compose and diff) and convert at the edge.

Generate SOAP request bodies

Build the JSON representation of a SOAP body programmatically, then run it through this tool to get a spec-compliant XML message.

Author RSS / Atom feeds from data

Store feed items as JSON in your CMS or database, and render the outward-facing XML on demand with this converter.

Round-trip test XML pipelines

When testing an XML → JSON → XML pipeline, use this tool to verify the second leg produces semantically equivalent XML.

Code Examples

Input JSON

{
  "book": {
    "@id": "b1",
    "title": "Refactoring",
    "author": "Martin Fowler"
  }
}

Output XML

<?xml version="1.0" encoding="UTF-8"?>
<book id="b1">
  <title>Refactoring</title>
  <author>Martin Fowler</author>
</book>

Do it in Node.js with fast-xml-parser

import { XMLBuilder } from "fast-xml-parser";
const builder = new XMLBuilder({ ignoreAttributes: false, attributeNamePrefix: "@", format: true });
const xml = builder.build(json);

Key Concepts

@ prefix convention
Keys starting with @ are hoisted out of the child element list and placed on the parent's opening tag as attributes. This is the mapping fast-xml-parser and jq's --xml output use.
#text convention
A key named #text (configurable) provides the element's text content when the same element also has attributes or child elements. Without it, a string value under the tag name is used directly as the body.
Array → repeated siblings
When a value is a JSON array, the tool emits the surrounding tag once per element — e.g. { "item": [1, 2, 3] } produces <item>1</item><item>2</item><item>3</item>.
Well-formed vs. valid
This tool produces well-formed XML (correct nesting, escaping, single root). It does not enforce any schema (DTD/XSD) — if your target system requires schema validation, that's a separate step.

Tips & Best Practices

  • XML element names cannot start with a digit or contain spaces. If your JSON keys break these rules, rename them (data_2024 instead of 2024_data) before conversion.
  • Boolean and number JSON values are stringified as-is (true, 42, 3.14). XML has no native types, so downstream code must interpret string content.
  • null JSON values become empty self-closing elements (<field/>), which is the closest XML equivalent to absent data.
  • When your target consumer expects <![CDATA[...]]> blocks (usually for HTML embedded in XML), you'll need to wrap the string manually — this tool does not emit CDATA.
  • If you're generating SOAP messages, wrap the payload in a soap:Envelope / soap:Body pair in your JSON structure first so the outer tags come out correctly.

Frequently Asked Questions

How does it decide the root element name?

If your JSON is a single-key object like { "library": ... }, the outer key becomes the root element. Otherwise the tool wraps the payload in a <root> element. You can override the name in the toolbar.

How are JSON arrays converted?

An array is emitted as repeated sibling elements sharing the same tag name — e.g. { "book": [ {...}, {...} ] } becomes <book>...</book><book>...</book>. This matches how fast-xml-parser and xml2js round-trip XML.

How do I add XML attributes from JSON?

Prefix the key with @ (default) — e.g. { "@id": "b1", "title": "..." } serializes to <book id="b1"><title>...</title></book>. Use the toolbar to switch to $ or _ if you're targeting a specific library convention.

Are special characters escaped correctly?

Yes. &, <, >, " and ' are replaced with their XML entity forms in both element text and attribute values. Tag names are validated against the XML naming rules and rejected with an error if invalid.

Is the output valid XML I can parse in any XML library?

Yes. It includes a <?xml version="1.0" encoding="UTF-8"?> declaration (optional, toggleable), uses only ASCII-safe entities, and follows XML 1.0 well-formedness rules.

Related Tools