JSON to XML

XML to JSON Converter Processed locally in your browser

Convert XML to JSON and JSON to XML online, locally in your browser.

Input
0
Examples
JSON result

Repeated elements (auto array) · 自动

@xxx is read as an attribute · Arrays become repeated elements · Special characters are escaped
XML and JSON are not fully equivalent; mixed content, attribute order and namespaces are not guaranteed to round-trip losslessly.
Privacy:Files and text are read and converted only in your browser. Nothing is uploaded, received, or stored by this site.

Online XML Generator with Root Elements, Arrays, Attributes and CDATA

What Is JSON to XML Conversion?

JSON to XML conversion transforms JSON data structures into XML documents. JSON represents information using objects, arrays and primitive data types, while XML organizes information through elements, attributes and text nodes. Both formats are widely used in API development, configuration files, data exchange and enterprise system integration.

NZTool JSON to XML converts JSON text into XML directly in your browser. It supports custom root element names, array item names, indentation, XML declarations, CDATA and strict element name validation. You can copy or download the result or switch to XML to JSON conversion. All input and conversion operations run locally in your browser without uploading data to a server.

How to Convert JSON to XML Online

  1. Open NZTool JSON to XML and select JSON → XML mode.
  2. Paste JSON into the input field or import a local JSON or TXT file.
  3. Check JSON syntax, including objects, arrays, quotation marks and brackets.
  4. Expand conversion settings if needed and configure the root element, array item name, indentation and XML declaration.
  5. Adjust CDATA and strict element name validation options when required.
  6. Click Convert to generate XML.
  7. Review the generated tags, attributes, array elements and text content.
  8. Copy or download the XML for use in APIs, configuration files or other applications.

Ordinary JSON objects can usually be converted directly. For top-level arrays, unusual property names and deeply nested structures, check the root element and array mapping rules first.

JSON to XML Example

The following JSON contains user information and multiple email addresses:

{
  "user": {
    "name": "Tom",
    "age": 25,
    "email": [
      "tom@example.com",
      "work@example.com"
    ]
  }
}

Mapping object keys to XML elements and array entries to repeated elements can produce:

<?xml version="1.0" encoding="UTF-8"?>
<user>
  <name>Tom</name>
  <age>25</age>
  <email>tom@example.com</email>
  <email>work@example.com</email>
</user>

This example illustrates common mappings for JSON objects, primitive values and arrays. The actual root and array element names depend on the selected settings.

How Are JSON Objects Converted into XML Elements?

JSON objects contain keys and values. During conversion, keys can become XML element names, while values become text content or nested elements.

For example:

{
  "product": {
    "name": "Laptop",
    "price": 5999,
    "stock": true
  }
}

Possible XML output:

<product>
  <name>Laptop</name>
  <price>5999</price>
  <stock>true</stock>
</product>

XML text does not preserve native JSON number or boolean types. When converting back to JSON, type detection may be necessary to restore those types.

How Are JSON Arrays Converted to XML?

JSON arrays represent multiple values or objects, but XML has no directly equivalent array type. Arrays are commonly represented as repeated elements or elements with a shared item name.

For example:

{
  "users": {
    "user": [
      {"name": "Tom"},
      {"name": "Alice"}
    ]
  }
}

Possible XML output:

<users>
  <user>
    <name>Tom</name>
  </user>
  <user>
    <name>Alice</name>
  </user>
</users>

For top-level arrays or arrays without a clear element name, configure a root and item name such as root and item. Match these settings to the XML structure expected by the receiving API.

How to Customize the XML Root Element

Every XML document must have one root element. JSON, however, allows objects, arrays and primitive values at the top level, so conversion requires an explicit root mapping rule.

NZTool provides a root element name setting, which can use root by default. You can specify another valid name for top-level arrays or data that requires a consistent wrapper.

For example, a top-level JSON array:

[
  {"id": 1},
  {"id": 2}
]

Can become:

<root>
  <item>
    <id>1</id>
  </item>
  <item>
    <id>2</id>
  </item>
</root>

If the top-level JSON object already contains a single usable element name, the converter may use it as the root according to its mapping rules and settings.

How to Convert JSON Properties into XML Attributes

XML attributes commonly describe identifiers, types and other element metadata. NZTool uses special property naming conventions to distinguish attributes from child elements.

For example, properties beginning with @ can represent XML attributes:

{
  "product": {
    "@id": "1001",
    "@category": "electronics",
    "name": "Laptop"
  }
}

Converted XML:

<product id="1001" category="electronics">
  <name>Laptop</name>
</product>

The name property becomes a child element, while @id and @category become attributes. Attribute names must follow XML naming rules, and special characters in attribute values must be escaped correctly.

What Do #text and #content Mean in JSON?

XML elements can contain attributes, text and child elements simultaneously. Special JSON properties help represent these structures.

PropertyPurposeExample
@idXML attributeid="1001"
#textElement text content<name>Tom</name>
#contentMixed content and orderingInterleaved text and child elements

For example:

{
  "message": {
    "@lang": "zh-cn",
    "#text": "你好"
  }
}

Can become:

<message lang="zh-cn">你好</message>

More complex XML with interleaved text and elements requires the converter's supported mixed-content mapping. JSON and XML are not fully equivalent, so lossless round trips are not guaranteed for every document.

How Does JSON to XML Handle Special Characters?

XML has strict rules for special characters. For example, ampersands and less-than signs in text require entity references, while quotation marks in attribute values must be handled correctly.

For example, JSON containing these literal characters:

{
  "message": "Tom & Jerry < Friends"
}

The XML output must escape them:

<message>Tom &amp; Jerry &lt; Friends</message>

Correct escaping prevents malformed XML. However, control characters forbidden by XML 1.0 must still be detected and rejected; ordinary escaping cannot make them valid.

What Is CDATA? Does JSON to XML Support It?

CDATA is an XML text representation that reduces the need to escape certain special characters individually. It is useful for code snippets, HTML text and other content containing markup characters.

For example:

<content><![CDATA[<div>Hello</div>]]></content>

NZTool provides a CDATA option to control text output. CDATA cannot directly contain the closing sequence ]]>. Such content must be split into safe CDATA sections or represented another way.

Can JSON to XML Add an XML Declaration?

Yes. The XML declaration option controls whether a declaration appears at the beginning of the output.

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

The declaration identifies the XML version and encoding. Whether it is required depends on the receiving system; some APIs expect only the root element without a declaration.

What Does Strict XML Name Validation Do?

XML element names must follow XML naming rules. JSON property names are more flexible and may contain spaces, begin with digits or use characters that are unsuitable for XML element names.

For example:

{
  "123name": "Tom"
}

123name is not a valid XML element name. With strict name validation enabled, the converter should report the invalid property rather than silently renaming it. This helps avoid changing the meaning of the original data.

For unusual properties that must be converted, rename the JSON keys first or define an explicit mapping appropriate for the target XML format.

Does JSON to XML Support Formatting and Indentation?

Yes. NZTool supports indentation with 2 or 4 spaces to make generated XML easier to read.

Formatting should improve readability without changing elements, attributes or text. For mixed content where text and child elements are interleaved, automatically inserted whitespace can affect meaning and should be handled carefully.

JSON to XML vs. XML to JSON

FeatureJSON to XMLXML to JSON
InputJSONXML
OutputXMLJSON
Main purposeGenerate XML documentsParse XML data
Root elementRequires an XML rootRoot preservation is optional
ArraysMapped to repeated XML elementsRepeated elements can become arrays
AttributesSpecial properties become XML attributesXML attributes become JSON properties
Result formatXML textJSON text

NZTool provides both conversion directions in one interface. Because the data models differ, converting back may not restore the exact original structure.

Common Uses for JSON to XML

  • API development: Convert JSON test data to XML for XML-based APIs.
  • System integration: Prepare XML for enterprise systems that require it.
  • Configuration generation: Generate XML configurations from structured JSON.
  • Data exchange: Convert common structured data between systems with different format requirements.
  • Development and debugging: Inspect XML mappings of objects, arrays, attributes and root elements.
  • Learning XML: Compare JSON and XML representations of elements, attributes and nesting.

Frequently Asked Questions

Can JSON be converted directly to XML?

Yes. Paste valid JSON, select JSON → XML mode and run the conversion. Complex structures may require mapping adjustments.

Do I need to install software?

No. NZTool parses and converts data directly in your browser.

Can JSON arrays be converted to XML?

Yes. Arrays usually become repeated elements. For top-level arrays, configure root and item element names.

Can I customize the XML root element?

Yes. Enter a root element name that matches your target API or configuration format.

Can JSON properties become XML attributes?

Yes. Under the converter's naming convention, properties beginning with @ become attributes, such as @id becoming id.

Can JSON to XML output CDATA?

Yes. A CDATA option is available, subject to XML's CDATA content restrictions.

Can I include an XML declaration?

Yes. Use the XML declaration switch to control whether it is included.

Are Chinese characters allowed in XML element names?

The XML standard permits Unicode characters, including many Chinese characters, in valid element names. Actual support also depends on the converter's name validation implementation.

Why does the converter report an invalid element name?

The JSON key may contain characters prohibited in XML names or begin with a digit. Rename the property or review strict name validation.

How is JSON null converted to XML?

XML has no native equivalent of JSON null. Depending on the mapping rules, it may become an empty element, empty text or another defined representation.

Are JSON number and boolean types preserved?

XML element values are primarily text, so numbers and booleans are generally serialized as text. Converting back may not restore their original types automatically.

Will converting JSON to XML and back produce identical JSON?

Not necessarily. Attributes, arrays, empty values, CDATA, text nodes and type information may be represented differently.

Can the XML output be formatted?

Yes. Choose an indentation setting to format the generated XML.

Can I download the XML file?

Yes. Copy the result or use Download to save the XML file.

Is my JSON uploaded to a server?

No. NZTool reads JSON and generates XML locally in your browser.

Free Online JSON to XML Converter

NZTool JSON to XML converts JSON objects, arrays and text into XML documents in your browser. Customize root and array item names, map XML attributes, configure CDATA and declarations, validate element names, adjust indentation, copy or download results and convert in both directions. No installation or upload required.
  • JSON to XML: Paste or import JSON to generate structured XML documents.
  • Custom root elements: Configure XML root and array item names.
  • Objects and arrays: Convert object properties into elements and arrays into repeated nodes.
  • Attributes and text: Map special properties such as @id and #text.
  • CDATA and declarations: Configure CDATA output and XML declarations.
  • Strict name validation: Detect property names that violate XML naming rules.
  • Formatting and export: Set indentation, copy, download and reverse convert.
  • Local privacy: Process JSON entirely in your browser without server uploads.
Use NZTool JSON to XML to prepare XML documents for API development, configuration files and data exchange. Check JSON syntax, root element names and special property mappings before conversion, then verify the generated elements, attributes and array structure. Because JSON and XML differ, complex data cannot always be converted back without changes.
Comments 0
No comments yet. Be the first to comment!
avatar
Comment content cannot be empty
0/255