A missing two-space indent in a Kubernetes YAML file took down our staging environment for 40 minutes. The error message was cryptic. The fix was one space character. YAML's significant whitespace is its most praised and most cursed feature simultaneously. After working with all three formats across production infrastructure, here is what I actually reach for and why.
Convert YAML to JSON locally β local processing.
Parse, validate, and convert between JSON and YAML in your browser. Your config files stay on your device.
Open YAML to JSON Converter βThe Same Config in All Three Formats
Here is a database configuration expressed in JSON, YAML, and TOML. Read all three and notice what your brain finds easiest β that instinct usually points to the right answer for your use case.
// JSON β no comments allowed, verbose punctuation
{
"database": {
"host": "localhost",
"port": 5432,
"name": "production_db",
"ssl": true,
"pool": {
"min": 2,
"max": 10,
"timeout": 30000
}
}
}# YAML β comments work, but whitespace is significant
# This is the production database config
database:
host: localhost
port: 5432 # PostgreSQL default
name: production_db
ssl: true
pool:
min: 2
max: 10
timeout: 30000 # 30 seconds in ms# TOML β explicit types, comments, no significant whitespace # Production database configuration [database] host = "localhost" port = 5432 # PostgreSQL default name = "production_db" ssl = true [database.pool] min = 2 max = 10 timeout = 30_000 # Underscores allowed in numbers for readability
JSON: Fast, Strict, Commentless
JSON is defined byIETF RFC 8259. Its rules are intentionally minimal: six data types (string, number, boolean, null, array, object), no comments, strict quoting requirements.
The no-comments restriction is a deliberate design choice. Douglas Crockford, who formalised JSON, removed comment support because comments were being used to embed parser directives β turning a data format into a config language. For data interchange (API responses, serialised state), this strictness is a feature. For configuration files, it is a constant frustration.
Where JSON excels: speed. JSON.parse() is a native browser function compiled directly into the JavaScript engine. It is 10β15Γ faster than js-yaml and comparable to the fastest compiled-language YAML parsers.
YAML: Readable but Treacherous
YAML's design goal was human readability above all else. It achieves this β a YAML config file is often easier to read than its JSON equivalent, especially for nested structures and multi-line strings.
But YAML hides serious parsing traps.
The Norway Problem β YAML's Famous Boolean Trap
In YAML 1.1, the following strings are all parsed as boolean values without quotes:
# YAML 1.1 boolean traps (22 values total) true: true, True, TRUE, yes, Yes, YES, on, On, ON false: false, False, FALSE, no, No, NO, off, Off, OFF # Real-world consequence: country codes in a config country_code: NO # β parsed as false (Norway's ISO code!) feature_flag: yes # β parsed as true (you wanted the string "yes") # Fix: always quote strings that might match boolean patterns country_code: "NO" feature_flag: "yes"
YAML 1.2 fixed this β only true and falseare boolean. But most parsers (including js-yaml below version 4.0, PyYAML, and Go's gopkg.in/yaml.v2) still implement YAML 1.1. Check your parser version before trusting unquoted strings.
Tabs Are Illegal in YAML
YAML prohibits tab characters for indentation. Only spaces are valid. Many code editors default to tabs for some file types β this causes silent parse failures in YAML files opened and edited by tab-defaulting editors.
# WRONG β tab character for indentation causes a parse error database: host: localhost # β tab here β INVALID YAML # Correct β spaces only database: host: localhost # β two spaces β valid
Implicit Type Coercion Surprises
YAML infers types from unquoted values. This causes data corruption in unexpected places:
# Type coercion surprises in YAML version: 1.0 # β float 1.0 (not string "1.0") phone: 07911123456 # β int 7911123456 (leading zero stripped!) hex_color: 0xFF # β int 255 (hex parsed!) date: 2026-07-02 # β datetime object (not string!) null_val: # β null (empty value is null) # These all need quoting to remain strings: version: "1.0" phone: "07911123456" hex_color: "0xFF" date: "2026-07-02"
TOML: The Underrated Alternative
TOML (Tom's Obvious Minimal Language) was created by Tom Preston-Werner (GitHub co-founder) specifically to be a configuration format without YAML's ambiguity problems.
TOML's type system is explicit: strings require quotes, integers and floats are distinguished, dates are a native type, and there is no implicit coercion. A TOML file never silently converts NO to false.
It is now the default configuration format for several major ecosystems:
- Rust: Cargo.toml (every Rust project)
- Python: pyproject.toml (PEP 517/518 packaging standard)
- Hugo: config.toml (static site generator)
- Zola, Nix, uv, Rye: all default to TOML
Full Format Comparison
| Feature | JSON | YAML | TOML |
|---|---|---|---|
| Comments | No | Yes (#) | Yes (#) |
| Significant whitespace | No | Yes (indentation-based) | No |
| Implicit type coercion | No | Yes (many edge cases) | No |
| Multi-line strings | Escaped \n only | Native (| and > blocks) | Native (""" blocks) |
| Native date type | No (use ISO string) | Yes (YAML 1.1, unreliable) | Yes (RFC 3339) |
| Parse speed (Node.js) | Native (fastest) | 10β15Γ slower than JSON | 2β5Γ slower than JSON |
| Browser native support | Yes (JSON.parse) | Requires library | Requires library |
| Schema validation | JSON Schema | Limited | Limited |
Edge Cases That Break Each Format
YAML Anchors β Powerful but Confusing
YAML supports anchors and aliases for reusing values across a file. This is useful for large configs but a debugging nightmare when overused:
# YAML anchor β define once defaults: &defaults retries: 3 timeout: 5000 # YAML alias β reuse the anchor (merges the values) production: <<: *defaults # Inherits retries: 3 and timeout: 5000 host: prod.example.com staging: <<: *defaults host: staging.example.com timeout: 10000 # Override just this value
Anchors work well when used sparingly. Files with anchors of anchors of anchors become very hard to debug. No equivalent exists in JSON or TOML.
JSON Trailing Commas β Still Broken in 2026
Standard JSON does not allow trailing commas. This is an endless source of parse errors:
// INVALID JSON β trailing comma after last element
{
"name": "FileMint",
"version": "2.0", // β trailing comma β JSON.parse() throws
}
// VALID JSON β no trailing comma
{
"name": "FileMint",
"version": "2.0"
}
// Note: JSONC (JSON with Comments) and JSON5 allow trailing commas
// Use these for config files read by tools that support them (VS Code, ESLint)YAML Multi-line String Modes
YAML has two multi-line string operators with different newline handling:| (literal, preserves newlines) and> (folded, collapses newlines to spaces). Using the wrong one produces unexpected whitespace in parsed strings:
# Literal block (|) β preserves every newline message: | Line one Line two # β "Line one Line two " # Folded block (>) β newlines become spaces (except blank lines) message: > Line one Line two # β "Line one Line two " # Folded is for prose. Literal is for code, SQL, or anything line-sensitive.
My Recommendation by Use Case
| Use Case | Format | Reason |
|---|---|---|
| REST API responses | JSON | Native browser parse, universal tooling support |
| Kubernetes / Docker configs | YAML (required) | Ecosystem standard β no practical alternative |
| Rust, Python project config | TOML | Cargo.toml, pyproject.toml β language ecosystem standard |
| ESLint, Prettier, TypeScript config | JSON or JSONC | Tool ecosystem uses JSON; JSONC adds comment support |
| GitHub Actions CI/CD workflows | YAML (required) | GitHub Actions format β YAML only |
| New project config (greenfield) | TOML | Unambiguous types, comments, no whitespace traps |
When you must use YAML: always quote strings that could match boolean patterns. Set your editor to show whitespace characters. Use a YAML linter (yamllint) in your CI pipeline. These three habits eliminate the class of bugs that cost me 40 minutes in production.
For API-level format decisions (not configuration files), our XML vs JSON comparison covers the performance and schema validation tradeoffs that apply when the format is used in network communication rather than local config files. If you need to convert between formats, our YAML to JSON converter runs entirely in your browser.
Convert YAML to JSON locally.
Paste your YAML and get clean JSON. Validates syntax as you type. local processing.
Open YAML to JSON Converter β