YAML to JSON Converter

Paste a YAML config to get formatted JSON, with anchors and aliases expanded. The YAML to JSON converter points to the exact line and column of any error.

Updated
Runs in your browser. Your data is not uploaded.
Converts as you type for inputs up to 200 KB.

How to use the YAML to JSON Converter

  1. Paste YAML into the input box, or upload a .yaml or .yml file up to 5 MB.
  2. Choose an Indent: 2 spaces, 4 spaces, or minified.
  3. Press Convert, then Copy the JSON or Download .json.

How it works

  • The input is parsed as YAML 1.2 with the core schema.
  • Anchors (&name), aliases (*name), and << merge keys are expanded into full copies of the data.
  • Comments are dropped, because JSON has no comments.
  • Several documents separated by --- become a JSON array, with a note.
  • Keys that aren't strings, such as numbers, are turned into strings. Timestamps stay strings.
  • Parsing is safe: custom tags are refused, nothing is turned into code or objects, and alias expansion is capped at 10,000 nodes to block "billion laughs" input.

Examples

Input:

base: &b
  retries: 3
prod:
  <<: *b
  host: api.example.com

Output:

{
  "base": {
    "retries": 3
  },
  "prod": {
    "retries": 3,
    "host": "api.example.com"
  }
}

Two documents separated by --- give a JSON array with 2 elements.

Why convert YAML to JSON

  • Tools that only read JSON. Some APIs, scripts, and validators accept JSON but not YAML.
  • Finding indentation mistakes. In YAML, one space too many can move a key into the wrong parent. The JSON output shows plainly where each key ended up.
  • Checking anchors and merges. The output expands every alias and << merge, so you can confirm the final values a program will see.

Limitations

  • Input is limited to 5 MB.
  • Tabs used for indentation give the error "YAML does not allow tabs for indentation".
  • Duplicate keys give an error instead of silently keeping one value.
  • Unknown or custom tags, such as !!python/object, give an error.

Frequently asked questions

What happens to YAML comments?

JSON has no comments, so they are removed.

Are anchors and aliases supported?

Yes. They are expanded into full copies of the referenced data, including << merge keys.

What if my file has several documents?

Each document separated by --- becomes one element of a JSON array.

Why do I get an error about tabs?

YAML allows only spaces for indentation. Replace the tabs with spaces.

Often used together with the YAML to JSON.