JSON
</>
XML
📄
YAML
JSON vs XML vs YAML
Three data formats, different strengths. Learn when to use each for APIs, configuration, and data exchange.
Quick Verdict
Use JSON for
APIs, web services, general data interchange
Use YAML for
Config files, DevOps, human-edited files
Use XML for
Documents, SOAP, legacy systems
Same Data, Three Formats
JSON~150 bytes
{
"name": "John Doe",
"age": 30,
"active": true,
"skills": ["JS", "Python"],
"address": {
"city": "NYC",
"zip": "10001"
}
}XML~280 bytes
<?xml version="1.0"?>
<person>
<name>John Doe</name>
<age>30</age>
<active>true</active>
<skills>
<skill>JS</skill>
<skill>Python</skill>
</skills>
<address>
<city>NYC</city>
<zip>10001</zip>
</address>
</person>YAML~100 bytes
name: John Doe age: 30 active: true skills: - JS - Python address: city: NYC zip: "10001"
Feature Comparison
| Feature | JSON | XML | YAML |
|---|---|---|---|
| File extension | .json | .xml | .yaml, .yml |
| Data types | 6 types (string, number, bool, null, object, array) | Everything is a string | Rich types + custom tags |
| Comments | Not allowed | <!-- comment --> | # comment |
| Readability | Good | Verbose | Excellent |
| Parse speed | Fastest | Moderate | Slowest |
| Schema support | JSON Schema | XSD, DTD | JSON Schema compatible |
| Namespace support | No | Yes | No |
| References | No | No | Yes (anchors) |
Which Format for Which Use Case?
REST APIsJSON
Industry standard, native browser support
Configuration filesYAML
Comments, readability, widely used in DevOps
Data interchangeJSON
Universal support, smaller payloads
Document markupXML
XHTML, SVG, mixed content
Package manifestsJSON
package.json, composer.json standardized
Infrastructure as CodeYAML
Kubernetes, Docker Compose, Ansible
SOAP servicesXML
Legacy protocol requirement
Frontend configJSON
tsconfig.json, eslint, prettier
JSON
✓ Pros
- Native JavaScript support
- Fastest parsing
- Smallest file size
- Universal API standard
- Simple, strict syntax
✗ Cons
- No comments allowed
- Verbose for config files
- No multiline strings
- Keys must be quoted
XML
✓ Pros
- Supports comments
- Namespace support
- Mature tooling (XSLT, XPath)
- Good for documents
- Schema validation (XSD)
✗ Cons
- Very verbose
- All values are strings
- Complex to parse
- Large file sizes
YAML
✓ Pros
- Most human-readable
- Comments supported
- Multiline strings
- Anchors and references
- JSON superset
✗ Cons
- Indentation-sensitive
- Slowest to parse
- Security concerns (code execution)
- Multiple ways to express same thing