DevToolsmith

YAML to JSON Converter

Paste YAML to get formatted JSON instantly. Anchors, aliases, merge keys and multi-document files are supported, and syntax errors are pinpointed to the exact line and column.

Runs 100% in your browser — nothing is uploaded

YAML
Tip: drop a file here274 chars · 274 bytes · 15 lines
JSON
426 chars · 426 bytes · 25 lines

Example

YAML
# GitHub Actions workflow
name: CI
on:
  push:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci && npm test
JSON
{
  "name": "CI",
  "on": {
    "push": {
      "branches": [
        "main"
      ]
    }
  },
  "jobs": {
    "test": {
      "runs-on": "ubuntu-latest",
      "steps": [
        {
          "uses": "actions/checkout@v4"
        },
        {
          "run": "npm ci && npm test"
        }
      ]
    }
  }
}

Anchors and merge keys

YAML can define a block once with an anchor (&defaults) and reuse it with an alias (*defaults). The merge key << copies its keys into another mapping. JSON has no such feature, so the converter expands everything:

YAML
defaults: &defaults
  adapter: postgres
  pool: 5

production:
  <<: *defaults
  database: app_prod
JSON
{
  "defaults": {
    "adapter": "postgres",
    "pool": 5
  },
  "production": {
    "adapter": "postgres",
    "pool": 5,
    "database": "app_prod"
  }
}

Common YAML errors and how to fix them

  • Tabs for indentation: YAML only allows spaces. Replace tabs with two spaces.
  • Inconsistent indentation: items of the same list or mapping must line up exactly.
  • Unquoted colons: title: Note: read me is ambiguous. Quote the value: title: "Note: read me".
  • Special characters at the start: values beginning with *, &, !, @ or a backtick must be quoted.
  • Duplicate keys: the same key twice in one mapping is an error in YAML 1.2.

Convert YAML to JSON in code

# yq
yq -o=json '.' config.yaml

# Python (PyYAML)
python -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))' < config.yaml

# Node.js (npm install yaml)
node -e 'const fs=require("fs"),YAML=require("yaml");console.log(JSON.stringify(YAML.parse(fs.readFileSync(0,"utf8")),null,2))' < config.yaml

Going the other way? Use JSON to YAML.

Frequently asked questions

How do I convert YAML to JSON?

Paste YAML into the tool above, or drop a .yaml or .yml file onto it. The JSON appears as you type, with 2- or 4-space indentation. If the YAML has a syntax error, the exact line and column are shown.

Does this support anchors, aliases and merge keys?

Yes. Anchors (&name) and aliases (*name) are expanded, and merge keys (<<: *name) are applied. That is how Docker Compose files, GitLab CI and Rails database.yml reuse configuration.

What happens with multiple YAML documents?

A file with several documents separated by --- (common in Kubernetes manifests) becomes a JSON array with one element per document.

Why is "on" a key in my GitHub Actions JSON and not true?

This converter follows YAML 1.2, the current spec, where only true and false are booleans. YAML 1.1 parsers turn on, off, yes and no into booleans too, which famously makes GitHub Actions’ on: key become true in some tools.

Are YAML comments kept?

No. JSON has no comment syntax, so comments are dropped during conversion. Keep the YAML as your source of truth if the comments matter.