CloudFormation accepts templates in either JSON or YAML. Both formats are functionally identical — the same template can be expressed in either, and CFN parses them into the same internal model. The choice is about authoring ergonomics, not capability. ## Tradeoff **JSON** - Strict, brace/bracket-delimited; ECMA-404 compliant - Easy for machines, verbose for humans - **No comments allowed** — this is a hard JSON-spec limitation, not a CFN choice - Workaround for documentation: put notes in the `Metadata` section - Backslashes in regex must be doubled (`\\d{4}`) **YAML** - Indentation-based, human-readable, less ceremony - Supports `#` inline comments anywhere - Indentation is load-bearing — inconsistent spacing causes silent structure errors - Regex stays single-escaped but must be quoted (`'\d{4}'`) ## CFN's YAML dialect CFN follows YAML 1.1 with **explicit exclusions**: - No tags: `binary`, `omap`, `pairs`, `set`, `timestamp` - No aliases (`&anchor` / `*reference`) - No hash merges (`<<:`) Aliases and hash merges are the YAML deduplication features people most often miss when porting templates from other YAML-driven tools (Ansible, GitHub Actions). CFN forces you to repeat or use intrinsic functions like `Fn::FindInMap` instead. ## Decision YAML is the default choice for hand-authored templates — comments matter, and the verbosity savings compound at scale. JSON is preferable when templates are machine-generated (CDK synth output, IaC generator) where readability isn't a goal. ## Related - [[CFN Template Structure Nine Sections]] - [[CFN Regex Support and Gotchas]]