Skip to content
JSON Tidy

YAML to JSON converter

Paste YAML or open a .yaml or .yml file, and you get formatted JSON back. If the YAML has an error, you’ll see the line and column. It all runs in your browser, so the file isn’t uploaded.

YAML

JSON

Anchors and merge keys

If your config defines a block once with an anchor (&defaults) and reuses it with an alias (*defaults) or a merge key (<<), the JSON gets a full copy of that block everywhere it’s used. JSON has no way to point to another part of the file.

# Shared by every environment
defaults: &defaults
  region: us-east-1
  timeout: 30

production:
  <<: *defaults
  replicas: 4
  timeout: 60
{
  "defaults": {
    "region": "us-east-1",
    "timeout": 30
  },
  "production": {
    "region": "us-east-1",
    "timeout": 60,
    "replicas": 4
  }
}

Values set next to the merge win over the shared ones, so production keeps its timeout of 60.

Multiple documents and comments

If the file has more than one document separated by ---, as Kubernetes manifests often do, you get a JSON array with one entry per document. Comments are dropped, since JSON doesn’t support them.

Why yes and no come out as strings

This converter follows YAML 1.2, where only true and false are booleans, so enabled: yes turns into "enabled": "yes". PyYAML and other older parsers would read it as true. If the file was written for one of those, an Ansible playbook for instance, check the output and change those values to true or false where needed.

Converting is also a quick way to check how a file is being read in general. If a port shows up as a string, or a list is nested one level deeper than you expected, it’s easy to see in the JSON.

Common YAML errors

Indentation causes most of them. Keys at the same level have to line up, and tabs aren’t allowed, which catches people out when they paste from an editor that indents with tabs.

The other usual one is an unquoted value with a colon and a space in it, like title: Note: read this first, or a value that starts with @ or a backtick. Quote the value and the error goes away. A key that appears twice in the same mapping is also an error.

Doing it in code

# Python, with PyYAML (pip install pyyaml)
import json, yaml
with open("config.yaml") as f:
    data = yaml.safe_load(f)
print(json.dumps(data, indent=2, default=str))

// JavaScript, with js-yaml (npm install js-yaml)
import yaml from "js-yaml";
const json = JSON.stringify(yaml.load(text), null, 2);

# Command line, with yq
yq -o json config.yaml

With PyYAML, unquoted dates load as Python date objects, and json.dumps won’t write those. default=str turns them into strings. If the file has several documents, use list(yaml.safe_load_all(f)) instead.

Files can be up to 2 MB. To browse or query the result, open it in the JSON formatter. To convert back, use JSON to YAML.