Tutorial · 5 min read

How to Convert docker-compose.yml to JSON

Docker Compose files are YAML. But many tools, APIs, and CI/CD pipelines prefer JSON. A YAML to JSON converter transforms your docker-compose.yml into clean, valid JSON in seconds.

1. Converting a Basic Docker Compose File

A standard docker-compose.yml converts to JSON with identical structure:

version: '3.8'
services:
  web:
    image: nginx:alpine
    ports:
      - "80:80"
  api:
    image: myapp:latest
    environment:
      - DEBUG=true

Becomes JSON:

{
  "version": "3.8",
  "services": {
    "web": {"image": "nginx:alpine", "ports": ["80:80"]},
    "api": {"image": "myapp:latest", "environment": ["DEBUG=true"]}
  }
}

The converter preserves data types — numbers stay numbers, booleans stay booleans, and strings stay strings.

2. Handling YAML Anchors and Aliases

Docker Compose files often use anchors to avoid repetition. The converter resolves them automatically:

x-logging: &default-logging
  driver: json-file
  options:
    max-size: "10m"

services:
  web:
    image: nginx
    logging: *default-logging
  api:
    image: myapp
    logging: *default-logging

In the JSON output, *default-logging is expanded to the full logging configuration for both services. No duplication in your YAML, but clean explicit JSON.

3. Multi-Document YAML (Kubernetes Manifests)

Kubernetes manifests use --- to separate multiple resources in one file. The converter handles this:

apiVersion: v1
kind: Service
metadata:
  name: my-app
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app

Each document separated by --- is parsed independently. The output shows each document as a separate JSON object — perfect for processing K8s manifests in automation scripts.

4. Comments and Data Types

Two common concerns when converting YAML to JSON:

This means a YAML value of true becomes JSON true (boolean), not "true" (string). For editing or validating the output, use the JSON Editor.

Try the Free YAML to JSON Converter

Paste docker-compose.yml, Kubernetes manifests, or any YAML — get clean JSON instantly.

Convert YAML to JSON Now →

Best Practices for YAML to JSON Conversion

Frequently Asked Questions

How do I convert docker-compose.yml to JSON?

Paste your docker-compose.yml into a YAML to JSON converter. It parses the YAML structure and outputs valid JSON with proper data types.

Does the converter support YAML anchors and aliases?

Yes. Anchors (&) and aliases (*) are resolved and expanded into full JSON values. No information is lost.

Can I convert multi-document YAML files?

Yes. Files with multiple documents separated by --- are parsed independently. Each document becomes a separate JSON output.

Can I convert Kubernetes manifests?

Yes. Kubernetes manifests (Deployment, Service, ConfigMap) are standard YAML and convert cleanly to JSON for automation and scripting.

Is my YAML data safe during conversion?

Yes. All conversion is 100% browser-based. Your YAML never leaves your computer. No server uploads, no storage, no tracking.

Looking for more guides? See the full JSONXX How To index.