Convert a Docker Compose file between YAML and JSON
A docker-compose.yml file converted to JSON and back. Useful for programmatic generation (Compose only accepts YAML on disk, but JSON is easier to template from code).
# context
docker-compose.yml on disk is always YAML. But teams that generate Compose files from a tool (Pulumi, Terraform output, custom scripts) often produce JSON-compatible structures first, then convert. The Compose schema is identical in both — Compose v3+ accepts JSON files renamed to .yml because every JSON document is also valid YAML 1.2.
# sample (JSON)
{
"services": {
"web": {
"image": "nginx:1.27",
"ports": ["80:80"],
"depends_on": ["db"],
"environment": {
"DATABASE_URL": "postgres://db:5432/app"
}
},
"db": {
"image": "postgres:16",
"volumes": ["dbdata:/var/lib/postgresql/data"],
"environment": {
"POSTGRES_PASSWORD": "changeme"
}
}
},
"volumes": {
"dbdata": {}
}
} → Open in JSON ↔ YAML converter (pre-filled)
# notes
- Compose accepts boolean strings differently per version. Always quote yes/no/on/off values: `"true"` not `true`.
- Port mappings as strings ("80:80") survive both directions. As objects ({ published: 80, target: 80 }) is more explicit and recommended for newer files.
- Environment variables with shell-style interpolation (${VAR}) round-trip correctly; the converter does not expand them.