Course contentsShow
← Cloud and Infrastructure
Lesson 860 of 2,98916. AWS CloudFormationFree lesson

YAML vs JSON Template Formats

Compare YAML and JSON syntax for CloudFormation templates and learn when to use each format.

YAML vs JSON Template Formats

What you'll learn: You'll understand the syntax differences between YAML and JSON for CloudFormation templates and when to choose each format.

The Two Languages CloudFormation Speaks

AWS CloudFormation accepts templates written in either JSON (JavaScript Object Notation) or YAML (YAML Ain't Markup Language). Both formats describe the exact same infrastructure, but they differ in readability and style—think of them as two dialects of the same language.

JSON Syntax

JSON uses curly braces {}, square brackets [], and requires strict punctuation:

{
  "Resources": {
    "MyBucket": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": "my-example-bucket"
      }
    }
  }
}

JSON requires commas between items, quotes around every key, and no comments are allowed.

YAML Syntax

YAML uses indentation (like Python) and is more human-friendly:

Resources:
  MyBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: my-example-bucket

YAML allows comments with #, doesn't need quotes in most cases, and eliminates visual clutter.

When to Use Each

Choose YAML when:

  • Writing templates by hand
  • You want readability and maintainability
  • You need inline comments for documentation

Choose JSON when:

  • Generating templates programmatically
  • Working with tools that output JSON
  • Your team has strict JSON-only policies

Most CloudFormation users prefer YAML for its cleaner syntax and comment support, but both are equally powerful and convert the same way to AWS infrastructure.

Key Takeaway: YAML and JSON are interchangeable formats for CloudFormation templates—YAML offers better readability for humans, while JSON suits automated generation, but both create identical stacks.