consolelog.tools

JSON to XML

Convert JSON to XML live — with @attributes / #text round-tripping, safe element-name sanitisation, and configurable root, indent & declaration.

About this ToolHow it works, benefits & use cases

Convert a JSON document into well-formed XML, generated live as you type. Each key becomes an element and arrays expand into repeated sibling elements with the same tag, so a list of items maps naturally onto XML. The converter understands two special keys for fuller fidelity: an "@attributes" object is emitted as XML attributes on the surrounding element, and a "#text" value becomes the element's text content — the same convention the companion XML to JSON tool produces, so values round-trip between the two. Element names that are not valid XML are sanitised automatically, and text and attribute values are XML-escaped so characters like &, < and > stay safe. You can name the root element, choose 2- or 4-space indentation, and optionally prepend an XML declaration. The output reports how many elements were generated and can be copied, downloaded as .xml, or shared — all processed in your browser with nothing uploaded.

How to Use

  1. 1Set the root element name (defaults to root) and choose 2- or 4-space indentation.
  2. 2Toggle "XML declaration" on or off depending on whether you want the <?xml …?> prolog.
  3. 3Paste your JSON into the input panel — the XML appears live — or click "Load example" to see the @attributes and #text conventions.
  4. 4Press "Convert to XML" to validate the JSON.
  5. 5Copy the XML, download it as output.xml, or share it via the generated URL.

Key Benefits

  • Maps JSON keys to elements and arrays to repeated sibling elements
  • Round-trips with the XML to JSON tool via "@attributes" and "#text" keys
  • Sanitises invalid element names and XML-escapes text and attribute values
  • Configurable root element name and 2- or 4-space indentation
  • Optional XML declaration prolog
  • Live preview with an element count, plus copy, .xml download and sharing
  • Runs entirely in the browser — your data is never uploaded

Common Use Cases

  • Producing an XML payload for a SOAP or legacy service from JSON data
  • Generating sample XML fixtures from a JSON object during testing
  • Adding XML attributes to elements using the "@attributes" convention
  • Converting configuration between JSON and XML representations
  • Building an RSS- or sitemap-style document where arrays become repeated nodes

Options

Prepend <?xml version="1.0" encoding="UTF-8"?>

0 characters · live · "@attributes" & "#text" keys supported

Paste JSON above to see the XML live.

Was this tool helpful?

Share Your Experience

Help others discover this tool!

Related tools