opyeb YAMLJSON

YAML vs JSON vs TOML — which one, when

2026-11-29 · 2 min read

All three hold the same data and each is good at something else. TOML and YAML suit files people read and edit; JSON suits data machines exchange.

Side by side

Whether comments exist, how sensitive the format is to indentation, and whether null can be expressed decide most real choices.

AspectYAMLJSONTOML
commentsyesnoyes
indentation sensitiveyesnono
nullyesyesno
top-level arrayyesyesno
deep nestingreads wellverboserepetitive tables
typical useKubernetes, CIAPIs, data exchangelanguage package config

Choose YAML when

The config has several levels of nesting mixed with lists. Kubernetes, CI and compose files are exactly that shape.

The cost is sensitivity to indentation and quotes, plus the YAML 1.1 versus 1.2 differences in how values are read.

Choose TOML when

The config is shallow with many keys: package metadata, tool settings. Every value has a clear type and comments are free-form.

It is a poor fit when the top level must be an array or nulls are needed. Use JSON or YAML for those.

Questions

Can JSON have comments?

Not in standard JSON. JSONC and JSON5 add them, but standard tools may reject those files, so configs are better in YAML or TOML.

Which languages support all three?

Python, Go, Rust and JavaScript all have libraries for each format. The 1.1 versus 1.2 YAML difference varies by library.

Sources

Every example here can be pasted into the converter as it is.

Open the converter