JSON vs YAML vs XML: When to Use What?

January 26, 2026 (2 min read)

When creating config files or deciding on an API response format, have you ever wondered "which one should I use?" JSON, YAML, XML—all three express data, but when is each one the best choice?

Side-by-Side Comparison

Let's represent the same data in all three formats.

JSON

{
  "name": "John Doe",
  "age": 30,
  "skills": ["JavaScript", "Python"],
  "address": {
    "city": "New York",
    "zip": "10001"
  }
}

YAML

name: John Doe
age: 30
skills:
  - JavaScript
  - Python
address:
  city: New York
  zip: "10001"

XML

<person>
  <name>John Doe</name>
  <age>30</age>
  <skills>
    <skill>JavaScript</skill>
    <skill>Python</skill>
  </skills>
  <address>
    <city>New York</city>
    <zip>10001</zip>
  </address>
</person>

You can already see the difference. YAML is the most concise, XML the most verbose.

JSON { "name": "kim", "tags": ["dev", "web"] } YAML name: kim tags: - dev - web XML <person> <name>kim</name> <tags> <tag>dev</tag> <tag>web</tag> </tags> </person> 45 bytes 31 bytes 94 bytes
The exact same record (one name + two tags) in each format — YAML 31 bytes, JSON 45 bytes, XML 94 bytes (UTF-8, newlines included)

JSON: The Web Standard

Pros:

  • Native to JavaScript (it's literally JavaScript Object Notation)
  • Supported by virtually every programming language
  • Fast parsing
  • De facto standard for web APIs

Cons:

  • No comments (inconvenient for config files)
  • Strict syntax (quotes, commas required)
  • Tedious for humans to edit manually

When to use: API responses, web data exchange, programmatic data storage

Standard JSON has no comments. JSONC and JSON5 allow them, and TypeScript's tsconfig.json and VS Code settings accept JSONC.

YAML: Human-Friendly

Pros:

  • Best readability (structure via indentation)
  • Supports comments (with #)
  • Quotes usually optional
  • Multiline string support

Cons:

  • Indentation errors break things (watch for tab/space mixing)
  • Parsing slower than JSON
  • Advanced features (anchors, aliases) can be confusing

When to use: Config files (Docker Compose, Kubernetes, GitHub Actions), files humans edit frequently

To avoid indentation errors, use 2 spaces instead of tabs, install an EditorConfig or YAML extension in your IDE, and add yamllint to your CI pipeline.

XML: Still Alive

Pros:

  • Schema validation (strict type checking with XSD)
  • Supports attributes
  • Namespaces prevent collisions
  • XSLT for transformations

Cons:

  • Verbose (sometimes more tags than data...)
  • Complex and slow parsing
  • Rarely used in modern web

When to use: Legacy systems, SOAP APIs, when strict schemas are required, office document formats (docx is internally XML)

XML is still used in Android layouts, Maven/Gradle build files, SVG and Office documents (OOXML).

Summary Table

JSON YAML XML
Readability Medium Good Poor
Comments No Yes Yes
Parse Speed Fast Medium Slow
Schema Validation JSON Schema Limited XSD (strict schemas)
Primary Use APIs, Web Config files Legacy, Docs