Lesson 2

YAML vs JSON

Choose the right format for configs and APIs.

YAML and JSON can represent the same data model, but they optimize for different workflows.

Readability

YAML removes braces and quotes in common cases, which makes large configs easier to scan:

database:
  host: localhost
  port: 5432

The JSON equivalent is valid but noisier for human editors.

Strictness

JSON is stricter and easier to parse safely at scale. That is why many APIs use JSON for untrusted input, while YAML is common for trusted, human-maintained config repos.

Comments and trailing commas

YAML allows # comments. JSON standard JSON does not. This matters when teams document non-obvious flags directly in CI or Helm files.

Conversion workflows

Teams often:

  • Export JSON from an API or generator
  • Convert to YAML for manual edits
  • Convert back to JSON for tools that only accept JSON

Round-trip conversion preserves data, but key order, quoting, and comments may change. Always review diffs after conversion.

When to prefer JSON

  • Public HTTP APIs and browser-facing payloads
  • Machine-generated logs and events
  • Pipelines that must reject ambiguous typing

When to prefer YAML

  • Kubernetes and Compose files checked into git
  • CI workflow definitions edited by developers
  • Application config with comments and multi-line strings

When you want to practice, use the related DevCove tool — optional, not part of this lesson.

Open related tool

Back to course overview