Development

JSON vs YAML syntax

Basic types, nesting, comments: the syntax differences between JSON and YAML, and the classic implicit-boolean trap.

Free Updated on September 11, 2026

Basic types

{
  "name": "Ana",
  "age": 32,
  "active": true,
  "notes": null,
  "tags": ["admin", "beta"]
}
name: Ana
age: 32
active: true
notes: null
tags:
  - admin
  - beta

Nested objects

{
  "address": {
    "city": "Paris",
    "zip": "75001"
  }
}
address:
  city: Paris
  zip: "75001"

Rules to remember

JSON YAML
Comments not supported yes, with #
Indentation free (braces) meaningful, spaces only
Quotes on strings required optional unless ambiguous
Trailing comma forbidden not applicable
Multi-line strings no yes, with `

In YAML, yes, no, on, off, true, false are sometimes parsed as booleans depending on the parser. Quote them if you want a real string: country: "no".

References and anchors in YAML

defaults: &defaults
  adapter: mysql
  timeout: 30

development:
  <<: *defaults
  database: dev_db

test:
  <<: *defaults
  database: test_db

&defaults defines a reusable anchor, <<: *defaults merges it into another block — handy for not repeating shared configuration.

When to choose which

Context Preferred format Why
REST API, data exchange JSON Native in JavaScript, a parser is everywhere
Configuration files YAML More readable for humans, comments allowed
Docker Compose, CI/CD, Kubernetes YAML The DevOps ecosystem's standard
Strict storage/serialisation JSON Unambiguous syntax, no indentation traps

YAML indentation must use spaces, never tabs — mixing the two is the most common mistake, and it usually produces a confusing parse error.

#Web
navigate open Esc close