Skip to content
← Blog
🔒 All in your browser 🚫 No uploads stored
Guide

YAML to JSON Conversion: Guide with Real-World Examples

Bill Crawford — Guide — February 2026 — 8 min read  ·  Last updated February 25, 2026

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.

Connect on LinkedIn →

Contents
  1. Why convert YAML to JSON?
  2. How to use the tool
  3. How YAML maps to JSON
  4. Worked examples
  5. YAML typing pitfalls
  6. What gets lost in conversion

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:

How to Use the Tool

1
Paste your YAML

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.

2
Get formatted JSON

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.

3
Copy or download

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.

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:

Frequently Asked Questions

What happens to YAML comments during conversion?
Comments are lost. JSON has no comment syntax, so all YAML comments (lines starting with #) are stripped during conversion. If comments contain important context, save the original YAML file separately.
Can I convert multi-document YAML files?
Multi-document YAML (files with --- separators) cannot be represented as a single JSON value. The tool converts the first document by default. For multi-document files, split them first and convert each document separately.
Are YAML anchors and aliases resolved?
Yes — anchors (&name) and aliases (*name) are resolved during conversion. The JSON output contains the fully expanded data with no references. This means the JSON file may be larger than the YAML source if anchors were used to avoid repetition.
Why did my YAML value change type after conversion?
YAML has implicit typing rules that can be surprising. Unquoted values like yes, no, on, off become booleans. Values like 1.0 become numbers even if you intended a string. Version numbers like 3.10 lose the trailing zero and become 3.1. Always quote values in YAML if you need them to stay as strings.

Related Tools & Guides

Further reading: MDN — Working with JSON · JSON.org Specification

BC
Bill Crawford
Founder, Data Conversion Center

Bill Crawford is a data systems developer and technical founder with over 30 years of professional experience in accounting, finance, and business operations.

He holds a Bachelor's degree in Accounting and has spent more than three decades working within financial and operational environments. Over the past 10 years, he has been heavily involved in the development, implementation, and refinement of financial and enterprise data systems for both Fortune 500 companies and smaller organizations.

His work bridges finance and technology — combining deep domain knowledge in structured reporting and accounting workflows with hands-on SQL development and database architecture experience.

Bill founded DataConversionCenter.com to build practical, browser-based tools that simplify complex data challenges, including:

Rather than focusing on theoretical examples, his tools and articles are informed by real-world challenges encountered in enterprise reporting systems, financial databases, and operational data environments.

Professional Background

Bill's mission is to reduce friction in data workflows — particularly for professionals working with structured financial, operational, and reporting data.