YAML to JSON Conversion: Guide with Real-World Examples
The YAML to JSON Converter transforms YAML configuration and data files into JSON format instantly in your browser. This is useful when you need to feed YAML configs into JSON-only APIs, parse them in languages without a YAML library, or debug unexpected values caused by YAML's implicit typing.
Ready to convert? Paste your YAML and get JSON instantly.
Open YAML to JSON ↗Why Convert YAML to JSON?
YAML is the standard format for configuration, but there are several situations where you need the same data as JSON:
- API payloads — most REST APIs accept JSON only. If your source of truth is a YAML config, you need to convert before sending.
- JavaScript/TypeScript projects —
JSON.parse()is built in; YAML parsing requires a third-party library likejs-yaml. - Debugging implicit types — YAML silently converts unquoted values like
notofalseand3.10to3.1. Converting to JSON reveals what the parser actually sees. - Tool compatibility — some tools (jq, JSON Schema validators, database importers) only accept JSON input.
- CI/CD pipelines — extracting values from YAML pipeline configs to pass as JSON to deployment scripts or API calls.
How to Use the Tool
Paste your YAML content into the input panel. The tool accepts single-document YAML with any nesting depth. If your YAML has syntax errors (bad indentation, mismatched quotes), the converter will show an error.
The output is pretty-printed JSON with 2-space indentation. All YAML-specific features (comments, anchors, tags) are resolved into their JSON equivalents. Everything runs in your browser — no server upload.
Copy the JSON to clipboard or download as a .json file. Use it directly in API calls, config files, or as input to other tools like the JSON Formatter or JSON Validator.
How YAML Maps to JSON
Mappings become objects
YAML key-value pairs become JSON object properties. Indentation is replaced by braces.
# YAML
database:
host: localhost
port: 5432
// JSON
{
"database": {
"host": "localhost",
"port": 5432
}
}
Sequences become arrays
YAML lists (items prefixed with -) become JSON arrays with square brackets.
# YAML
allowed_origins:
- https://example.com
- https://staging.example.com
// JSON
{
"allowed_origins": [
"https://example.com",
"https://staging.example.com"
]
}
Scalars become primitives
YAML scalars are converted to the appropriate JSON type based on YAML's implicit typing rules: unquoted numbers become JSON numbers, true/false become JSON booleans, null and ~ become JSON null, and everything else becomes a JSON string.
Worked Examples
Docker Compose file
# YAML input
version: "3.8"
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: myapp
POSTGRES_USER: admin
POSTGRES_PASSWORD: secret
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata:
// JSON output
{
"version": "3.8",
"services": {
"postgres": {
"image": "postgres:16-alpine",
"environment": {
"POSTGRES_DB": "myapp",
"POSTGRES_USER": "admin",
"POSTGRES_PASSWORD": "secret"
},
"ports": ["5432:5432"],
"volumes": ["pgdata:/var/lib/postgresql/data"]
}
},
"volumes": {
"pgdata": null
}
}
Note: The empty pgdata: key with no value becomes null in JSON. This is correct YAML behavior — an empty value is interpreted as null.
GitHub Actions workflow
# YAML input
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: npm run build
- name: Deploy
run: ./deploy.sh
env:
TOKEN: ${{ secrets.DEPLOY_TOKEN }}
// JSON output
{
"name": "Deploy",
"on": {
"push": {
"branches": ["main"]
}
},
"jobs": {
"deploy": {
"runs-on": "ubuntu-latest",
"steps": [
{ "uses": "actions/checkout@v4" },
{ "name": "Build", "run": "npm run build" },
{
"name": "Deploy",
"run": "./deploy.sh",
"env": { "TOKEN": "${{ secrets.DEPLOY_TOKEN }}" }
}
]
}
}
}
YAML with anchors and aliases
# YAML input
defaults: &defaults
timeout: 30
retries: 3
production:
<<: *defaults
url: https://api.example.com
staging:
<<: *defaults
url: https://staging.api.example.com
retries: 5
// JSON output
{
"defaults": { "timeout": 30, "retries": 3 },
"production": {
"timeout": 30,
"retries": 3,
"url": "https://api.example.com"
},
"staging": {
"timeout": 30,
"retries": 5,
"url": "https://staging.api.example.com"
}
}
Anchors are fully resolved. The &defaults anchor and *defaults aliases are expanded into their values. Notice that staging overrides retries to 5 — the merge key (<<) applies defaults first, then local values take precedence.
YAML Typing Pitfalls
YAML's implicit typing is the biggest source of bugs when working with config files. Converting to JSON is actually a great way to catch these issues because JSON makes the types explicit.
nobecomesfalse— the stringsyes,no,on,off,y,nare all interpreted as booleans in YAML 1.1. The infamous Norway problem: a country code ofNObecomesfalse.3.10becomes3.1— YAML parses unquoted decimals as floating-point numbers. Version strings like3.10lose the trailing zero. Always quote version numbers.1_000becomes1000— YAML supports underscores as number separators. This is usually intentional, but can surprise you if1_000was meant as a string.- Timestamps — values like
2026-02-26may be interpreted as dates in some YAML parsers, producing unexpected output in JSON. - Octal numbers — a leading zero like
0755is an octal number in YAML 1.1 (493 in decimal). In YAML 1.2 this was changed, but many parsers still follow 1.1 rules.
Rule of thumb: If a YAML value should be a string and it looks like it could be a number, boolean, or date, always wrap it in quotes. When in doubt, quote it.
What Gets Lost in Conversion
YAML to JSON is not fully lossless. These YAML features have no JSON equivalent:
- Comments — JSON has no comment syntax. All
#comments are stripped. - Anchors and aliases — resolved into their expanded form. The JSON output has no concept of references or deduplication.
- Multi-line string style — YAML's
|(literal) and>(folded) block scalars are converted to regular JSON strings with\nescape sequences. The formatting intent is lost. - Custom tags — YAML tags like
!!binaryor!!timestampare resolved or dropped. - Document markers —
---and...have no JSON equivalent. Multi-document YAML files require splitting before conversion.
