JSON GUIDE · 3 MIN READ

JSON vs YAML for configuration

Understand indentation, comments, scalar types, and safe conversion between JSON and YAML.

Readability comes with parsing choices

JSON uses explicit braces, brackets, and quoted names. YAML commonly uses indentation and supports comments, making hand-maintained configuration less repetitive. Indentation is structural in YAML, so changing leading spaces can change the data rather than only its appearance.

YAML supports features beyond ordinary JSON values. Anchors and aliases can reuse structures, and custom tags depend on the reader. A file accepted by one application's YAML parser can behave differently in another if their versions or schemas differ.

service:
  name: api
  enabled: true
  ports:
    - 8080

Check values after conversion

Quote strings that resemble dates, booleans, or numbers when their textual form matters. After conversion, inspect identifiers with leading zeros and settings with null or empty values. JSON output cannot carry YAML comments or preserve the original indentation style.

Use a safe parser for untrusted YAML and set limits on aliases and document size. JSONSlate handles one document at a time with aliases disabled. It cannot infer application-specific meaning from a custom tag.

Put it into practice

Further reading

← All JSON guides