What is XML ↔ JSON conversion?
XML and JSON are both text formats for structured data, but they model the same information differently. XML uses nested elements and attributes; JSON uses objects, arrays, and native values. This converter translates between the two so you can move data across systems, API specifications, configuration files, and tooling.
The conversion is a data conversion, not a byte-for-byte copy: comments are dropped, formatting is normalized, and XML's attribute/text distinction is represented with dedicated keys.
Converting XML to JSON
The root element becomes the single top-level property, and the mapping inside follows a small, predictable rule set:
- Attributes become
@name properties (for example @id). - Character data becomes a
#text property when the element also has attributes or child elements; a pure-text element maps directly to its string value. - Repeated sibling elements become arrays; a single child element stays a single value.
- Empty elements (or whitespace-only elements) map to
null. - Comments and formatting whitespace are ignored.
# in: XML
<user id="123">
<name>Ada Lovelace</name>
<roles>
<role>admin</role>
<role>editor</role>
</roles>
<active>true</active>
</user>
# out: JSON
{
"user": {
"@id": "123",
"name": "Ada Lovelace",
"roles": ["admin", "editor"],
"active": "true"
}
}Converting JSON to XML
A root element name wraps the document, and every object property becomes a child element. Key names that are not valid XML names are sanitized with an underscore prefix. Values are serialized with these rules:
- Strings, numbers, booleans become element text, with
<, >, and & escaped. - Arrays of objects merge their properties under the parent element, producing repeated sibling elements for shared property names — the XML equivalent of a JSON array.
- Primitive arrays wrap every item in a
<value> element. - null and empty objects become empty elements like
<key/>. - Control characters that XML does not permit are replaced with the Unicode replacement character, keeping round-trips safe.
Safety and limits
For safety, documents that declare a <!DOCTYPE> or <!ENTITY> are rejected instead of parsed. External entities, internal entity expansion, and network access are never attempted, and no requests are made while parsing.
Mixed content is only partially supported: character data interleaved with child elements is concatenated into #text, and the original order of text and child elements is not preserved. Deeply formatted documents have their formatting whitespace dropped.
Privacy
Conversion runs entirely in your browser. The XML and JSON documents you paste are not uploaded to TechFixGen servers and are not included in analytics events. No account or signup is required. Need to check a JSON document first? Try the JSON Validator.