YAML Validation, Linting, and Troubleshooting

Common syntax errors, duplicate keys, parser checks, and validation workflows for debugging YAML faster.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Common YAML errors
Missing space after colon
name:John

# Show a syntax issue many parsers reject.

Bad list indentation
users:
- name: Jonathan
 role: admin

# Illustrate how list nesting can break parsing.

Duplicate key example
app:
  port: 8080
  port: 9090

# Show why repeated keys are dangerous.

Run strict linting on a file
yamllint config.yaml

# Catch common syntax and style problems in one pass.

## Parser and conversion debugging
Debug with Python safe_load
python - <<'PY'
import yaml, sys
with open('broken.yaml') as f:
    print(yaml.safe_load(f))
PY

# Confirm whether a parser can load a YAML document.

Parse YAML with Ruby
ruby -e 'require "yaml"; p YAML.load_file("config.yaml")'

# Use Ruby's YAML parser to validate a file.

Round-trip through JSON
yq -o=json '.' config.yaml | jq '.'

# Convert YAML to JSON to inspect the normalized data model.

Review YAML changes carefully
git diff --word-diff=color config.yaml

# Use Git diff modes that make structural edits easier to inspect.

Recommended next

No recommendations yet.