YAML or JSON

Choosing Between YAML and JSON Templates

Both formats parse into the same structure. YAML suits hand-written templates: it allows comments, needs few quotes or braces, and has short forms such as !Ref BooksTable for {"Ref": "BooksTable"}. JSON suits generated templates (the CDK 24 emits JSON) and tools such as jq 133,477 . CloudFormation 24 supports YAML 1.1 without aliases, hash merges or the binary, omap, pairs, set and timestamp tags, so Compose-style anchors are not available. AWS 24 's open-source cfn-flip 999 (github.com/awslabs/aws-cfn-template-flip (https://github.com/awslabs/aws-cfn-template-flip 999 ), Apache-2.0, pipx 21,050 install cfn-flip) converts in either direction. Run it on the file that this section's slices make up:

The TableName output of Section 7.3.6, converted to JSON by cfn-flipShell
cd ~/v5-ch7/booknest/infra
cfn-flip booknest-data.yaml | jq '.Outputs.TableName'
Output
{
  "Value": {
    "Ref": "BooksTable"
  },
  "Export": {
    "Name": {
      "Fn::Sub": "booknest-${Stage}-table-name"
    }
  }
}

One YAML trap: unquoted, {Name: !Sub booknest-${Stage}-table-name} fails to parse, because the braces of ${Stage} end the flow mapping early (cfn-lint 2,641 : E0000 did not find expected ',' or '}'). Quote such strings.