JSON

XML ↔ JSON Converter

Convert XML to JSON and JSON to XML safely in your browser.

0 characters
0 characters
Ctrl+Enter to convert
Enter XML to convert.

Your data stays private

This tool runs directly in your browser. The content you enter is processed locally and is not sent to TechFixGen servers. No account or signup is required.

XML ↔ JSON conversion, explained

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.

Frequently asked questions

How are XML attributes represented in JSON?

Attributes become object properties prefixed with @, such as @id or @type. Character data inside the same element is stored under a #text property, so both kinds of content survive the conversion.

Why do repeated elements become arrays?

A document with several <item> siblings would collide if each overwrote the previous one. Repeated sibling elements are grouped into an array, while a single child element stays a single value — the same shape most JSON APIs use.

What happens to elements that contain both text and child elements?

This is mixed content. Direct character data is concatenated into a #text property and element ordering between text and children is not preserved. Most structured documents avoid mixed content, so this rarely matters in practice.

Why does the converter reject DOCTYPE and ENTITY declarations?

Such declarations can reference external entities or expand into large internal entities, which are unsafe to parse. The converter refuses these documents entirely — no entity expansion or network request is ever attempted.

How are arrays converted to XML?

An array of objects merges each object's properties under the parent element, producing repeated sibling elements for shared property names. Any other array wraps every item in a <value> element.

Is my XML or JSON uploaded anywhere?

No. Conversion happens entirely in your browser. The documents you paste are not uploaded to TechFixGen servers and are not included in analytics events.