
YAML vs JSON: What's the Difference and When to Use Each
If you've worked with config files, Docker, Kubernetes, or any CI/CD system, you've encountered YAML. If you've built APIs, you know JSON. But when should you use which? The Syntax Difference JSON: { "name" : "my-app" , "version" : "1.0.0" , "features" : { "auth" : true , "cache" : false }, "ports" : [ 3000 , 8080 ] } YAML (same data): name : my-app version : 1.0.0 features : auth : true cache : false ports : - 3000 - 8080 YAML is less verbose and more readable. But it has strict indentation rules. YAML Gotchas 1. Indentation matters (use spaces, not tabs) # Wrong parent : child : value # Tab indented - BROKEN # Correct parent : child : value # 2 spaces - WORKS 2. Strings don't need quotes... but sometimes do version : " 1.0" # Quotes needed - without quotes, YAML reads 1.0 as a float enabled : " true" # Quotes needed - without, YAML reads as boolean port : 3000 # No quotes needed for integers 3. Multi-line strings description : | This is a multi-line string that preserves newlines. su
Continue reading on Dev.to Webdev
Opens in a new tab



