Skip to content

JSON To XML

Convert JSON into escaped, typed XML with a documented deterministic mapping, custom root name, and no uploads.

Privacy: your files never leave your device. All processing happens locally in your browser.

How to use

  1. 1.Paste valid JSON and enter a simple XML root element name.
  2. 2.Choose pretty printed or compact output, then select Convert to XML.
  3. 3.Review the type attributes and escaped keys, copy the XML, and validate it against the receiving system’s actual mapping or schema.

About JSON To XML

JSON to XML converts valid JSON into well-formed XML using a documented typed mapping. Paste an object, array, or primitive value, choose a safe root element name, select pretty or compact output, and copy the result. Processing stays inside the browser and is bounded to 500,000 input characters and 64 nesting levels.

JSON and XML do not have one universal one-to-one conversion standard. JSON has objects, arrays, strings, numbers, booleans, and null. XML has elements, attributes, text, namespaces, and mixed content. This tool does not hide that mismatch. Instead, every generated element receives a type attribute so downstream readers can distinguish a JSON number from the string containing the same digits, an array from an object, and null from an empty string.

Object keys that are simple XML names become element names. The accepted bounded form starts with an ASCII letter or underscore and continues with letters, digits, underscores, periods, or hyphens. Names beginning with xml in any letter case are reserved and are not emitted directly. A key that does not meet the rule becomes an item element with the original key stored in an escaped key attribute.

Arrays become a parent element marked type=array, with each member rendered as an item child in its original order. Objects are marked type=object and retain JavaScript’s parsed property order. Strings, numbers, and booleans become text with a matching type attribute. Null becomes a self-closing element marked type=null. Empty objects and arrays remain distinguishable through their type attributes.

XML-sensitive characters are escaped. Ampersand becomes &, less-than becomes <, and greater-than becomes > in text. Double quotes are additionally escaped inside key attributes. The converter generates a UTF-8 XML declaration. It never inserts pasted text as markup, so a JSON string containing a tag remains text rather than becoming an executable or structural XML element.

The default pretty mode uses two-space indentation and line breaks for inspection. Compact mode removes formatting whitespace but keeps the same elements, attributes, order, and values. Neither mode reformats the original JSON number lexeme: JSON parsing first converts numbers to JavaScript numeric values, so insignificant lexical details such as trailing decimal zeroes are not preserved.

The mapping does not represent XML namespaces, attributes sourced from JSON keys, comments, processing instructions, CDATA sections, document type declarations, or mixed text-and-element content. It also does not guarantee compatibility with a vendor’s different JSON-to-XML convention. If an API, schema, or integration defines a required mapping, follow that contract instead of assuming this output matches it.

The 64-level depth limit prevents excessively nested input from exhausting the call stack, while the character limit bounds browser work. Invalid JSON, invalid root names, and reserved xml-prefixed root names produce errors before output. Tests cover objects, arrays, primitive types, null, empty arrays, escaping, invalid keys, pretty output, compact output, malformed JSON, and root validation.

For best results, validate the JSON first, use a root name expected by the receiving system, convert a representative sample, and parse the XML with the target system before processing a larger dataset. If round-trip fidelity is required, document this exact typed mapping on both sides or use a schema-controlled transformation. This page does not upload, save, validate against XSD, or send the output to an endpoint.

Methodology & sources

Parse bounded JSON with the browser JSON parser; validate a simple non-xml-prefixed root name; recursively map objects, arrays, strings, numbers, booleans, and null to elements carrying explicit type attributes; map unsafe keys to item elements with escaped key attributes; escape XML text and attributes; cap nesting at 64; and serialize with either two-space indentation or no formatting whitespace. Do not claim a universal mapping or XSD validation.

Frequently asked questions

Is there one standard JSON-to-XML mapping?
No. This tool uses a documented typed mapping and does not claim universal compatibility.
How are arrays represented?
An array becomes an element marked type=array with ordered item children.
What happens to invalid XML key names?
They become item elements whose escaped key attribute preserves the original JSON key.
Can pasted strings become XML markup?
No. XML-sensitive characters are escaped, so JSON strings remain text content.

Developer Tools guides

View all