JSON to XML

Free online JSON to XML converter that auto-converts JSON objects or arrays into standard XML format. JSON objects are wrapped in a <root> node, arrays in <root><item> repeating nodes. Pretty-print output, 100% in your browser without uploads.

Related

About JSON to XML: convert JSON data into standard XML format

JSON to XML is the process of converting JSON-formatted data (JSON objects or JSON arrays) into XML (eXtensible Markup Language) format. JSON (JavaScript Object Notation) is the standard data format for modern Web APIs; XML is the traditional data format for enterprise systems, SOAP Web Services, configuration files, and Office documents. Each format has its strengths: JSON is concise and easy to parse; XML is strict, self-describing, and widely supports namespaces and schema validation. In development, it is often necessary to convert JSON data to XML to interface with legacy systems or meet specific business needs; this tool automates that process.

The tool's core is the recursive conversion of JSON nodes into XML elements based on the xmlbuilder2 library. The conversion rules are simple: keys of JSON objects become XML element names, values become element text content; arrays are wrapped as repeating <item> child elements. JSON objects are wrapped in a <root> node by default, and arrays in <root><item>...</item></root>. The prettyPrint: true parameter enables beautified output with automatic indentation and line breaks.

The mapping from arrays to repeating elements is a key design decision in JSON to XML. XML has no native array concept and represents list data through repeating elements (e.g. <item>1</item><item>2</item>). The tool uniformly uses <item> as the array element child node name, with the outer <root> wrapping forming a standard structure that matches XML data exchange conventions. The generated XML is compatible with RSS, SOAP, enterprise XML protocols, and other common application scenarios.

XML generated in prettyPrint mode is far more readable than minify mode. Developers can open it directly in text editors, XML editors (XMLSpy, oXygen), or browsers, without first running it through xmllint or other formatting tools. This design is particularly useful when debugging and manually adjusting XML.

The rules for mapping JSON basic types to XML are simple: strings are used directly as element text (e.g. <name>Alice</name>); numbers are converted to string form (e.g. <age>30</age>); booleans are converted to the strings 'true'/'false'; null becomes an empty element or is omitted. All non-string types lose their type information in XML, requiring a schema or type hint to restore them at parse time.

Nested objects recursively generate the corresponding XML tree. For example, { "user": { "name": "Alice", "age": 30 } } becomes <root><user><name>Alice</name><age>30</age></user></root>. This structure preserves the original JSON's hierarchy, making it easy for XML parsers to query via XPath.

The tool uses pure element mapping: all JSON data is converted to XML elements, with no XML attributes. This is because element mapping is more intuitive, more readable, and supports more complex nested structures. If your business needs the attribute form (e.g. <node attr='value'/>), manually adjust the generated XML or use XSLT transformation.

Real-time conversion is a practical feature of the tool. The tool converts 400ms after typing stops, with 5 keyboard shortcuts (macOS ⇧⌘+Enter/F/O/D/K), so users can quickly complete common operations like convert, format, upload, download, and clear without mouse clicks.

JSON error self-repair improves the tool's fault tolerance. Real-world JSON often has small issues like trailing commas, single quotes, missing quotes, and comments. The built-in tryFixJSON function is automatically invoked when JSON.parse fails and tries to fix common errors; if the repair succeeds, the user is notified; if not, the right panel shows the specific error location and reason.

Pure client-side processing is the core architecture of this tool. All JSON parsing and XML generation run in browser JavaScript; nothing is sent to a server. There are two key benefits: first, the JSON may contain sensitive information (user data, API keys, internal business), and local processing completely eliminates the leak risk; second, the conversion speed is limited only by the device's CPU, so files under 1 MB finish almost instantly without waiting for network round-trips.

Use Cases

  • Convert REST API JSON responses to XML for traditional enterprise systems (SAP, Oracle EBS) that only accept XML.
  • Generate RSS feeds, Atom feeds, or sitemap.xml from JSON configuration for content publishing and SEO indexing.
  • Prepare message bodies for SOAP Web Services (XML payload inside the SOAP envelope) for enterprise service bus integration.
  • Convert JSON test fixtures to XML format for testing legacy XML parsing code or JAXB data binding.
  • Convert database-exported JSON to XML for indexing and querying in XML databases (BaseX, eXist).
  • Convert JSON exported from Excel to XML for use in Office Open XML documents or XLIFF translation files.
  • Convert API mock data (JSON) to XML format for testing WSDL clients or gRPC XML serialization.
  • Teach the conversion relationship between JSON and XML data formats, helping understand the mapping logic between data serialization formats.

How to Use

  1. Paste JSON into the left editor, click the Upload button to select a .json/.txt file, or click Sample to load the built-in example.
  2. The tool converts automatically with a 400ms debounce. View the generated XML code on the right with CodeMirror XML syntax highlighting for readability.
  3. Click the Format button (⇧⌘+F) to re-indent the JSON to 2 spaces for easier reading of complex structures.
  4. Click Copy to copy the XML to the clipboard, or click Download to save it as an output.xml file (MIME: text/xml).
  5. To change the root node name or add namespaces, manually edit the generated XML.
  6. Paste the XML into the target system (API client, XML editor, or enterprise system) for use.

Features

  • Smart node wrapping: JSON objects are automatically wrapped in a <root> node, arrays in <root><item> repeating nodes, matching XML data exchange conventions.
  • Pretty-print output: powered by xmlbuilder2's prettyPrint mode, the generated XML includes indentation and line breaks for excellent readability.
  • Real-time auto conversion: the tool converts 400ms after typing stops, with 5 keyboard shortcuts to speed up common operations.
  • JSON error self-repair: the built-in tryFixJSON routine handles trailing commas, single quotes, and missing key quotes automatically.
  • Basic type compatibility: null, boolean, number, string and other JSON basic types are all converted to XML element text.
  • Recursive nested objects: nested objects of any depth are recursively converted into the corresponding XML element tree.
  • Multi-level array support: one-dimensional and multi-dimensional arrays are correctly converted into <item> repeating node structures.
  • Dual JSON/XML highlighting: the left side uses CodeMirror JSON syntax highlighting, the right side uses XML syntax highlighting for clarity.
  • Complete shortcut system: 5 common shortcuts (convert/format/upload/download/clear) for macOS and Windows/Linux.
  • Copy and download: copy the result to the clipboard with one click, or download as a standard output.xml file (MIME: text/xml).
  • 100% browser-side: all JSON parsing and XML generation happen in client-side JavaScript; the original JSON never leaves your device.
  • History recovery: the tool automatically saves the last 200 history items, and restores the previous input on page load.

FAQ

How do I convert JSON to XML format?

Paste your JSON into the left editor and the tool automatically converts it to standard XML format. JSON objects are wrapped in a <root> node (e.g. { "name": "Alice" } becomes <root><name>Alice</name></root>), and arrays are wrapped in <root><item>...</item> repeating nodes. The conversion runs 400ms after typing stops.

How are JSON arrays converted to XML?

JSON arrays are automatically wrapped in a two-level structure: the outer <root> node and inner <item> repeating nodes. For example [{"a":1},{"a":2}] becomes <root><item><a>1</a></item><item><a>2</a></item></root>. This design matches common XML data exchange conventions (RSS, SOAP messages).

Is the generated XML pretty-printed?

Yes. The tool uses xmlbuilder2's prettyPrint mode to generate nicely indented XML with line breaks. Developers can paste the result directly into SOAP tools, XML editors, or configuration files without manual formatting.

Which JSON data structures are supported?

All valid JSON data structures are supported: primitives (null, boolean, number, string), arrays of any depth, and nested objects of any depth. Arrays at every level are wrapped in <item> repeating nodes. JSON containing functions, Symbols, or undefined values is not valid JSON and cannot be converted.

Can the downloaded XML be used directly with SOAP or RSS?

Yes. The generated XML conforms to the standard XML 1.0 specification and can be parsed by most SOAP tools, RSS readers, XML databases (BaseX, eXist), and enterprise systems (SAP, Oracle). The download is named output.xml and can be read by any XML processing tool.

What if my JSON fails to parse?

When the JSON contains trailing commas, missing quotes, or single quotes instead of double quotes, the tool automatically calls tryFixJSON to attempt a repair. If the repair succeeds, you will be notified; if not, the right panel shows the exact error location and reason. You can also use the 2/4-space indent to reformat and try again.

Can I customize the XML root node name?

This tool uniformly uses root as the root node name and item for array children. These are the most universal XML data exchange conventions. If you need to customize them, manually edit the generated XML using your text editor's find-and-replace, or wrap your JSON with a custom key (e.g. { "response": {...} } will produce <root><response>...</response></root>).

How are JSON numbers and booleans represented in XML?

XML has no native number or boolean type; all values are converted to strings. For example, true in JSON becomes <isActive>true</isActive>, and 30 becomes <age>30</age>. At parse time the XML parser converts strings back per schema or type hints. If you need to preserve type information, use JSON Schema or DTD/XSD validation.

Does the tool support XML namespaces?

The tool generates standard XML without namespaces, suitable for most general use cases. If you need SOAP or WSDL XML with namespaces, you can manually edit the generated XML to add xmlns declarations, or use a dedicated SOAP toolchain.

Does the tool support XML attributes?

No. The tool uses pure element mapping: all JSON keys become XML elements and all values become element text content. If you need attribute-style XML (e.g. <node attr='value'/>), manually adjust the generated XML or use XSLT transformation.

Which input file types are supported?

The tool supports .json and .txt files (UTF-8 encoded). Click the Upload button to select a local file; the tool reads it through the browser's native FileReader API without uploading to a server. After upload, the content is automatically filled into the input box and triggers conversion.

What keyboard shortcuts are available?

The tool supports these shortcuts: on macOS, ⇧⌘+Enter to convert, ⇧⌘+F to format, ⇧⌘+O to upload, ⇧⌘+D to download, ⇧⌘+K to clear; on Windows/Linux, use Ctrl instead of ⌘. These shortcuts follow mainstream JSON editor conventions and significantly speed up your workflow.

Troubleshooting

The generated XML has a root node called root. Can I change it?

The tool uniformly uses root as the root node name (with item for array elements). If your business needs a custom name (such as <response> or <data>), there are two options: 1) manually edit the generated XML using your text editor's find-and-replace to change <root> to the target name; 2) wrap your JSON with a key (e.g. {"response": {...}}), which generates <root><response>...</response></root>, then use find-and-replace to remove the outer <root>.

XML parse error 'unclosed token' - what to do?

The cause is usually that JSON strings contain XML special characters (<, >, &) that were not properly escaped. The tool automatically converts these characters to XML entities (&lt; &gt; &amp;), but rare edge cases (like CDATA sections or comments) may need manual handling. Check the JSON for < and > characters and confirm they are data content, not accidental tag starts.

How do I customize the array element tag name (not item)?

The tool uniformly uses <item> as the array element child node name (matching RSS, SOAP, and other universal conventions). If your business needs a different name (such as <row> or <entry>), manually edit the generated XML and use find-and-replace to replace <item> with the target name, and adjust the closing tag </item> accordingly.

JSON numbers became strings and lost their type. What to do?

XML has no native number type, so all values are converted to strings. If you need to distinguish types at parse time, the options are: 1) use an XSD schema to validate the XML and specify element types (xs:integer, xs:boolean); 2) pre-name keys in the JSON to hint types (e.g. price_string, count_number); 3) use an XSLT script after conversion to convert types by business rules.

How do I keep numbers as numeric type in XML?

XML 1.0 has no native number type. If you must preserve type information: 1) use an XSD schema with <xs:element name='age' type='xs:integer'/> declarations; 2) use JSON Schema combined with an XML Schema conversion tool; 3) add an XSI namespace to the data envelope (xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance').

What can I open the downloaded .xml file with?

The download output.xml is a UTF-8 encoded standard XML file. You can open it with any text editor (VS Code, Sublime, Notepad++) or a professional XML editor (XMLSpy, oXygen). You can also drag it directly into a browser (Chrome, Firefox) to view the formatted tree structure. SOAP/RSS readers, enterprise middleware, and XML databases (BaseX, eXist) can also read it directly.

Will JSON containing emoji or non-ASCII characters cause errors?

No. The tool supports the full UTF-8 encoding, including Chinese, Japanese, Korean, and emoji Unicode characters. The xmlbuilder2 library automatically handles XML entity escaping, so emoji and non-ASCII text will appear as-is in the XML elements without special handling.

Glossary

JSON (JavaScript Object Notation)
Lightweight data-interchange format based on JavaScript object syntax but independent of any programming language. Supports six basic types: object ({}), array ([]), string, number, boolean, and null. Widely used for REST APIs, frontend-backend transport, configuration files, and logs.
XML (eXtensible Markup Language)
Extensible markup language, defined by W3C in 1998. Uses angle-bracket tags to describe data structure and content, and supports namespaces, schema validation, and XSLT transformation. It is the standard format for SOAP Web Services, Office Open XML, RSS, and Atom.
xmlbuilder2
JavaScript XML building library for programmatically generating structured XML documents. Supports namespaces, attributes, pretty-print output, CDATA sections, comments, and other advanced features. This tool uses this library to implement automatic JSON to XML conversion.
Node wrapping (root / item)
The XML node naming convention of this tool: JSON objects are uniformly wrapped in a <root> node, and elements of JSON arrays are uniformly wrapped in <item> repeating child nodes. This naming avoids conflicts with user-data keys and follows common XML data exchange conventions.
prettyPrint
Output mode of the xmlbuilder2 library. When enabled, the generated XML automatically includes indentation and line breaks (such as 2-space indentation), making it highly readable; when disabled, the output is compact without whitespace (minified). This tool enables prettyPrint by default.
SOAP (Simple Object Access Protocol)
XML-based Web service communication protocol. SOAP messages are wrapped in a SOAP envelope (XML namespace) and contain a header and body (XML payload). This tool can generate the XML payload needed for a SOAP body; you can then add the envelope manually.
RSS / Atom feed
XML-based content syndication formats. RSS 2.0 organizes content in a <rss><channel><item> structure, while Atom uses a <feed><entry> structure. The <root><item> pattern generated by this tool is similar to RSS and can serve as an intermediate step in an RSS generator.
Element vs attribute
Two ways to represent data in XML. Elements are wrapped in start/end tags (e.g. <name>Alice</name>), while attributes use key='value' form (e.g. <user name='Alice'/>). This tool uses pure element mapping and does not use attributes.
CDATA section
Special XML syntax <![CDATA[...]]> for embedding text containing special characters (such as <, >, &) without escaping. This tool does not generate CDATA sections by default; special characters are automatically escaped as XML entities (such as &lt; &gt; &amp;).
XML namespace
A mechanism to avoid element name conflicts using the xmlns attribute, in the form xmlns:prefix='uri'. Often used in SOAP (http://schemas.xmlsoap.org/soap/envelope/) and XHTML standards. This tool does not automatically add namespaces; add them manually when needed.
XPath
XML path query language for locating nodes in an XML document. For example, /root/user/name can query the name element under the user element under the root element. The XML structure generated by this tool is convenient for XPath queries.
XSLT
XML Stylesheet Language for Transformations, used to convert one XML format to another (such as XML to HTML, XML to PDF). The simple XML structure generated by this tool is convenient for XSLT post-processing.
tryFixJSON
The tool's built-in JSON repair routine that handles trailing commas, single quotes used instead of double quotes, missing key quotes, comments, and other common JSON syntax errors. It is automatically invoked when JSON.parse fails; if the repair succeeds, the user is notified and conversion continues.

JSON-to-XML element mapping rules

The tool's mapping rules from JSON to XML, based on xmlbuilder2:

JSON valueExampleXML elementMapping rule
string"Alice"<name>Alice</name>String used directly as element text content
number30<age>30</age>Number converted to string form (type info lost)
booleantrue<isActive>true</isActive>Boolean converted to strings 'true'/'false'
nullnull<field></field> or omittednull becomes empty element (xmlbuilder2 default)
object{"a":1}<root><a>1</a></root>Object wrapped in <root>, keys become child elements
array of objects[{"a":1}]<root><item><a>1</a></item></root>Array wrapped in <item> repeating nodes
nested object{"user":{"name":"x"}}<root><user><name>x</name></user></root>Nested objects recursively generate the element tree
nested array[[1,2]]<root><item><item>1</item><item>2</item></item></root>Multi-level arrays recursively wrap <item>

JSON vs XML format comparison

A comparison of the two data formats across different dimensions, to help understand when to choose JSON or XML:

DimensionJSONXMLNotes
Syntax{ } : [ ] concise< > </> verboseJSON syntax is more concise; XML tags are more verbose but readable
Data typesNative number/bool/nullAll stringsJSON preserves types; XML needs schema validation
ArraysNative [1,2,3]Repeating elements <i>1</i><i>2</i>JSON arrays are concise; XML arrays rely on naming conventions
CommentsNot supported (standard)<!-- comment -->XML supports comments; JSON standard does not (only JSON5/JSONC)
NamespacesNonexmlns supportedXML namespaces avoid name conflicts in large documents
Schema validationJSON SchemaXSD / DTDBoth have mature schema validation mechanisms
Parse performanceFaster (~3-5x)Slower (tag overhead)JSON parsing is simpler; XML parsing is more complex
Use casesREST API, frontend-backendSOAP, enterprise, OfficeModern web uses JSON; traditional enterprise uses XML

XML special character escaping rules

The tool's automatic escaping rules when JSON strings contain XML special characters:

Special charXML entityJSON exampleXML output
<&lt;"<"<field>&lt;</field>
>&gt;">"<field>&gt;</field>
&&amp;"&"<field>&amp;</field>
"&quot;"\""<field>&quot;</field>
'&apos;"'"<field>&apos;</field>
Tab&#9;"\t"<field>&#9;</field>
Newline&#10;"\n"<field>&#10;</field>

Privacy & Security

This JSON to XML tool runs entirely in your browser. JSON parsing, XML generation, and pretty-printing all happen in client-side JavaScript (powered by the xmlbuilder2 library); nothing is sent to any server. File uploads use the browser's native FileReader API and never go through an intermediate service. The tool uses no tracking cookies and collects no input or usage data. All input and output are cleared from memory as soon as the page is closed or refreshed. Safe to use for JSON that contains sensitive business data or internal API responses.

Authoritative References