TR

Home / Guides / What Is XML? The Difference Between XML and JSON, and How to Convert

What Is XML? The Difference Between XML and JSON, and How to Convert

Updated: October 13, 2026 · AracMerkezi

▶ Open XML Formatter

XML (Extensible Markup Language) is a markup language that describes data with tags. Sitemap files, RSS feeds, the internal structure of Office documents, SOAP services, and many enterprise systems still use XML.

A basic example

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

<person>

<name>Ayşe</name>

<age>30</age>

<tag>php</tag>

<tag>js</tag>

</person>

Syntax rules

  1. The document must have a single root element.
  2. Every opened tag must be closed: <name>Ayşe</name>.
  3. Tag names are case-sensitive: <Name> and <name> are different.
  4. Elements must be nested correctly; <a><b></a></b> is invalid.
  5. Attribute values are written in quotes: <person id="7">.
  6. Special characters must be escaped: & → &amp;, < → &lt;, > → &gt;.

Violating any of these rules makes the document not “well-formed” and causes the parser to report an error. The XML Formatter indents the document and shows errors of this kind.

Differences between XML and JSON

FeatureXMLJSON
StructureTags and attributesObjects and arrays
CommentsYes (<!-- -->)No
Data typesEverything is text (typed via a schema)Text, number, boolean, null
SizeMore verbose, largerMore compact
NamespacesSupportedNone

Which should you choose?

Converting XML to JSON

The conversion is not one-to-one, because the two formats have different models:

The example above becomes roughly {"person": {"name": "Ayşe", "age": "30", "tag": ["php", "js"]}}. The XML to JSON Converter does this in your browser; for the reverse direction, use the JSON to XML Converter. Note that numbers come through as text after conversion.

Security note

XML parsers can be vulnerable to external entity (XXE) attacks if they are not configured. When processing XML from an untrusted source on a server, disable the parser's external entity resolution. Converter tools in the browser do not send your data to a server.

Attribute or child element?

The same information can be written in two ways: <person id="7"><name>Ayşe</name></person> or <person><id>7</id><name>Ayşe</name></person>. A general approach is to use attributes for identifiers and metadata and child elements for the actual content. Since attributes and child elements may be represented differently when converting to JSON, pay attention to the tool's settings.

Real-life examples

What is a namespace?

It prevents tags with the same name from different sources from getting mixed up: <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">. When converting documents that contain a namespace to JSON, you may see prefixes and addresses appear as extra keys; this is expected.

Debugging tips

  1. If the parser gives an error like “Opening and ending tag mismatch,” look for the tag that is not closed or is closed in the wrong order.
  2. If there is an & in the text, make sure it has been turned into &amp;; this is the most common mistake.
  3. If there is an invisible character (BOM) or whitespace at the start of the document, the XML declaration may be considered invalid.
  4. The encoding declaration and the actual file encoding must be the same.

Limitations

The tools expect well-formed XML; they do not perform schema (XSD) validation. With very large documents, the browser's memory limit applies.

Frequently asked questions

What is the main difference between XML and JSON?

XML carries data with tags and attributes, JSON with objects and arrays; JSON is more compact, while XML offers features such as comments and namespaces.

What does well-formed XML mean?

XML that has a single root element, with tags correctly opened and closed and special characters escaped.

Can XML be converted to JSON one-to-one?

Not always; repeated elements, attributes, and mixed content may not have a natural JSON equivalent.

Tools mentioned in this guide

More guides

This article is for general information only and is not legal, financial or medical advice. We are not an official institution.