Paste your YAML below to convert it to JSON:

Loading...

Why Convert YAML to JSON?

While YAML is great for human-readable configs, JSON is the standard for APIs, data interchange, and programmatic manipulation. Converting YAML to JSON lets you use config data in applications and services.

Example Conversion

YAML:

server:
  host: localhost
  port: 8080
  ssl: true
database:
  connection: postgres://localhost/mydb
  pool_size: 10

JSON:

{
  "server": {
    "host": "localhost",
    "port": 8080,
    "ssl": true
  },
  "database": {
    "connection": "postgres://localhost/mydb",
    "pool_size": 10
  }
}

YAML Features Supported

YAML FeatureJSON Equivalent
Mappings (key: value)Objects
Sequences (- item)Arrays
Inline arrays [a, b, c]Arrays
Multi-line strings (|, >)Strings with newlines
true/yes/ontrue
null/~null

Common Use Cases

  • API integration — Convert YAML configs to JSON for REST API calls
  • Kubernetes debugging — Get JSON output for kubectl commands
  • Config validation — Validate YAML structure using JSON Schema
  • Data processing — Parse YAML files in languages with better JSON support
  • Documentation — Generate JSON examples from YAML source files

YAML Gotchas

YAML has some surprising behaviors that affect conversion:

The Norway Problem

# YAML interprets these as booleans!
countries:
  - NO    # false
  - YES   # true

Solution: Quote values that look like booleans: "NO"

Numbers vs Strings

version: 1.0   # Number 1.0
version: "1.0" # String "1.0"
zip: 01234     # Octal number!
zip: "01234"   # String "01234"

Programmatic Conversion

JavaScript (Node.js)

const yaml = require('js-yaml');
const fs = require('fs');

const doc = yaml.load(fs.readFileSync('config.yaml', 'utf8'));
const json = JSON.stringify(doc, null, 2);
console.log(json);

Python

import yaml
import json

with open('config.yaml') as f:
    data = yaml.safe_load(f)
    
json_string = json.dumps(data, indent=2)
print(json_string)

Command Line (with yq)

# Convert YAML file to JSON
yq -o=json config.yaml > config.json

# Or pipe from stdin
cat config.yaml | yq -o=json

Pro Tips

  • 💡 Watch indentation — YAML is whitespace-sensitive. Inconsistent indentation causes parse errors.
  • 💡 Comments are lost — JSON doesn't support comments, so YAML comments won't transfer.
  • 💡 Validate the output — Use the JSON Validator to ensure correct JSON syntax.

Related Tools