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.
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
- Check indentation first. YAML is indentation-sensitive. Inconsistent spacing is the #1 cause of conversion errors. Use 2-space indentation consistently.
- Verify anchor resolution. After conversion, review anchor-heavy files to confirm all aliases expanded correctly.
- Add a trailing newline. Some YAML parsers require a trailing newline. If the converter shows errors, add a blank line at the end.
- Validate the JSON output. After conversion, validate the output in the JSON Editor. See our JSON validation guide for details.
- Use JSON with JSON-only tools. The JSON output works with tools that don't support YAML natively, like certain CI/CD systems and API testing frameworks.
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.
4. Comments and Data Types
Two common concerns when converting YAML to JSON:
This means a YAML value of
truebecomes JSONtrue(boolean), not"true"(string). For editing or validating the output, use the JSON Editor.