C.W.K.
Stream
Lesson 04 of 08 · published

Lists & Maps — Block Style and Flow Style

~10 min · yaml, lists, maps, flow-style

Level 0Plaintext
0 XP0/64 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

Two ways to write the same data

Block style — the YAML look

Lists use - with a space, one item per line. Maps use key: value, one pair per line. Indentation defines nesting. This is what 95% of YAML in the wild looks like.

Flow style — the JSON look

Lists use [a, b, c]. Maps use {key: value, key: value}. Same data, JSON-shaped. Useful for short inline values where block style is overkill (a single-line list, a small map).

Mixing block and flow

You can put flow inside block. tags: [ai, daughter, engineer] is a one-line list inside a larger block document. The reverse — block inside flow — is technically allowed but reads poorly.

Principle: use block style for anything that benefits from line-by-line review (lists of dependencies, env-var maps, multi-step CI jobs). Use flow style only for short inline collections where the block form would just add noise. The 'compact JSON inside YAML' aesthetic is a smell.

Code

Block-style list·yaml
fruits:
  - apple
  - banana
  - cherry

# Or, equivalently, with indented hyphens:
dependencies:
- requests
- pyyaml
- httpx
Block-style map·yaml
server:
  host: localhost
  port: 8000
  ssl: false
Flow style — same data, JSON look·yaml
fruits: [apple, banana, cherry]
server: { host: localhost, port: 8000, ssl: false }
Block of maps (the K8s/CI shape)·yaml
containers:
  - name: api
    image: ghcr.io/cwk/api:1.0
    ports:
      - containerPort: 8000
  - name: worker
    image: ghcr.io/cwk/worker:1.0
    env:
      - name: ENVIRONMENT
        value: production

External links

Exercise

Take a docker-compose.yaml or a GitHub workflow file from your projects. Identify which sections use block style and which use flow. Convert one block-style list to flow (or vice versa) and feel the trade-off — readability vs vertical space — directly.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.