~/json-yaml-converter

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

# other examples