format.CoShareX
HomeBlogConvertersHow to Convert JSON to XML
Converters

How to Convert JSON to XML

Published 2026-08-10
4 min read
By CoShareX

Converting JSON datasets to XML is a common requirement when integrating modern APIs with legacy web services or enterprise systems. While JSON represents data as objects and arrays, XML uses hierarchical element tags, nested structures, and attributes.

In this guide, we'll explain how to convert JSON files to standard XML structures.

Mapping Keys to Element Tags

When converting JSON properties to XML:

  • Object keys are transformed into opening and closing XML tags (e.g. <key>value</key>).
  • Array items are converted to sibling tags sharing the same element name.
  • Nested JSON objects map to parent-child XML tags.

Input JSON:

json
1
2
3
4
5
6
{
  "user": {
    "name": "Bob",
    "roles": ["member", "editor"]
  }
}

Output XML:

xml
1
2
3
4
5
<user>
  <name>Bob</name>
  <roles>member</roles>
  <roles>editor</roles>
</user>
Featured Tool

JSON to XML

Convert JSON key-value pairs into tags-based XML.

Attributes vs Elements

To format values as attributes (e.g., <user id="101">) rather than nested tags, prefix the JSON keys with @ (for example, "@id": 101). Many XML serialization libraries recognize this pattern and compile the value directly as an element attribute.