YAML reference

YAML syntax reference for configuration and data files

Understand indentation, mappings, sequences, scalars, quoting, block text, booleans, null values, anchors, and conversion concerns.

11 min read Reviewed July 19, 2026 Professional reference

Document summary

A practical YAML reference that emphasizes indentation, ambiguous scalar values, safe parsing, and predictable conversion to JSON.

Key takeaways

  • Indentation defines structure and tabs should not be used for indentation.
  • Plain scalars can be interpreted differently by parser versions and schemas.
  • Validate configuration with the same parser used by the target application.
01

Indentation defines YAML structure

Mappings use key-value pairs, while sequences use a hyphen for each item. Child content is indented consistently with spaces. Tabs are not portable indentation.

Invalid
service:
        name: api
 ports:
  - 80
Valid
service:
  name: api
  ports:
    - 80
02

Mappings and sequences can be nested

StructureExample concept
Mappingname: api
Sequence- api - worker
Sequence of mappings- name: api port: 8080
Mapping containing sequenceports: - 80 - 443
03

Quote ambiguous scalar values

Plain scalars are convenient, but values that resemble booleans, nulls, dates, numbers, or punctuation-heavy strings may be interpreted by the parser.

Quote values when their exact string representation matters. Use block scalars for multi-line text.

Invalid
version: 01
enabled: yes
date: 2026-07-19
Valid
version: "01"
enabled: true
date: "2026-07-19"
04

Use literal and folded block styles intentionally

The | style preserves line breaks, while > folds many line breaks into spaces. Chomping indicators can control the final newline.

Use block text for certificates, scripts, descriptions, and messages only when the destination expects the resulting newline behavior.

05

Use anchors and aliases sparingly

Anchors and aliases can reuse nodes, and merge behavior is supported by some YAML workflows. They reduce repetition but can make configuration harder to understand and do not map cleanly to every target format.

Avoid aliases from untrusted input with unsafe loaders. Use a safe parser configuration appropriate to the application.

06

Review YAML to JSON conversion

JSON supports only string object keys and a smaller set of scalar types. Comments, anchors, aliases, tags, and formatting choices do not survive ordinary conversion.

Validate the converted values, especially dates, large numbers, nulls, and quoted strings.

  1. 1

    Parse with the target YAML version and safe schema.

  2. 2

    Inspect inferred scalar types.

  3. 3

    Resolve or remove aliases if required.

  4. 4

    Convert to JSON.

  5. 5

    Compare important values and structure.

  6. 6

    Validate against a schema when available.

Jump to tool

Open the YAML Formatter and validate a sample

Open tool