Skip to content
ToolPlankDEV
JSON Tools
100% In-Browser Execution

Updated:

YAML to JSON Converter

Paste YAML and get JSON as you type. This yaml to json converter resolves anchors and merge keys, reads files with several documents, points to the line and column of any error and lets you choose indent, key order and YAML version. Nothing is uploaded.

Options:

YAML

Input
0 chars · 0 lines

JSON

Ready
Processing in browser...
0 chars · 0 linesUpdates as you type

Notes

Notes about documents, custom tags and values JSON cannot hold appear here when there are any.

Processed on your device. Your text is not sent to our servers.

More free tools you may need next.

Quick Guide

How to use YAML to JSON

Simple step-by-step instructions to get the exact output you need.

  1. 01

    Paste your YAML

    Paste it into the left box, press Paste, or open a .yaml or .yml file. Example loads a Compose style file that uses an anchor and merge keys.

  2. 02

    Read the JSON

    The JSON appears as you type. If the YAML has a mistake, the message gives the line and column and explains the usual cause, such as a tab in the indentation.

  3. 03

    Set the output

    Choose 2 spaces, 4 spaces, a tab or minified output, the YAML version, whether to resolve merge keys, sorted keys, first document only, and whether to escape non-ASCII characters.

  4. 04

    Copy or download

    Press Copy to use the JSON, or Download to save it as a .json file. Notes under the result list anything JSON could not hold.

How to convert YAML to JSON

To convert yaml to json, the tool parses your YAML into data, resolves anchors, aliases and merge keys, and writes the data as JSON. Comments are dropped, because JSON has no way to hold them.

The built-in example is a Compose style file in which two services share settings through an anchor. The result has 15 keys over 29 lines. The anchored settings are copied into both services, so the JSON has no << keys and no aliases left:

JSON
    "web": {
      "restart": "unless-stopped",
      "environment": [
        "LOG_LEVEL=info"
      ],
      "image": "nginx:1.25",
      "ports": [
        "80:80"
      ]
    },

Convert YAML to JSON online with anchors and merge keys

An anchor, written &name, marks a block you want to reuse. An alias, written *name, inserts a copy. A merge key, <<: *name, copies the keys of the anchored map into the current map, and any key you write yourself overrides the copy. JSON has none of these, so the converter expands them.

Resolve merge keys is on by default. Turn it off to keep a literal "<<" key in the output. An alias that points to an anchor that does not exist is reported as an error, with the name of the missing anchor.

YAML to JSON for files with several documents

A YAML file can hold several documents separated by ---. Kubernetes files often do. JSON holds one value, so when the file has more than one document the result is an array with one item for each, and a note tells you how many were found. Turn on First document only to convert just the first one.

YAML 1.1 and 1.2: yes, no, on and off

The two YAML versions disagree about plain words. With YAML 1.2, the default, yes, no, on, off, y and n are ordinary text. With YAML 1.1 they are true and false. Dates differ too: in 1.1, 2020-01-02 becomes a timestamp and is written in JSON as 2020-01-02T00:00:00.000Z, while in 1.2 it stays as the text you wrote.

Pick the version of the program that will read your file. Ansible, which uses PyYAML, follows 1.1. Many newer libraries follow 1.2. When in doubt, quote the value in the YAML file and both versions agree.

YAML errors with line and column

  • Tabs are not allowed for indentation. Use spaces. The message points at the line with the tab.
  • Items at the same level must line up exactly, or you get an indentation error.
  • The same key twice in one block is reported, because most parsers keep only one of them. For files over 150,000 characters this check is skipped, and a note says so.
  • A colon after a key must be followed by a space. A text value that contains a colon followed by a space needs quotes.
  • An alias such as *name needs an earlier &name.

What JSON cannot hold

When your YAML uses features outside JSON, a note under the result says what happened:

  • Custom tags such as !Ref or !Sub from CloudFormation are ignored and the value is kept as plain data. The note lists the tags it saw.
  • Values like .nan and .inf become null, because JSON has no way to write them.
  • Whole numbers larger than 9,007,199,254,740,991 may be rounded.
  • Keys that are not text, such as 1, true or null, become text keys.
  • Binary values become Base64 text, and sets become lists.

YAML to JSON on the command line and in Python

Bash
yq -o=json config.yaml > config.json
Python
import json, sys, yaml

print(json.dumps(yaml.safe_load(sys.stdin), indent=2))

To go the other way, use JSON to YAML. If your file is TOML instead, TOML to JSON reads it. If the JSON you need is stored as a string with backslashes, JSON Unescape restores it. Spreadsheet data is covered by Excel to JSON, and JSONL Viewer reads files with one JSON value per line.

Limits

  • Comments are not kept, and neither are the anchors themselves. The data they point to is.
  • Keys that look like whole numbers are moved to the front in numeric order. That comes from how JavaScript stores object keys.
  • Very large files take a few seconds, because the whole file is parsed in your browser.

Your YAML is converted in your browser. It is not uploaded or stored. See the Privacy Policy for details.

Frequently Asked Questions

Technical Q&A for YAML to JSON

Common questions about edge cases, character encoding, and privacy guarantees.

Paste your YAML into the left box. The JSON appears on the right at once. Press Copy or Download to use it.

Read the file with yaml.safe_load from the PyYAML package and write it with json.dumps. This page gives the same result without installing anything.

With yq installed, run yq -o=json config.yaml > config.json. Without any tool, paste the file contents into this page.

They are expanded. Each alias becomes a full copy of the anchored data, and a merge key copies its keys into the map, with your own keys taking priority.

Yes. The result is an array with one item for each document. Turn on First document only if you want just the first.

It depends on the YAML version. YAML 1.2 keeps yes as text, while YAML 1.1 reads it as true. Choose the version the program that reads your file uses.

The message gives the line and column and a hint. The usual causes are tabs in the indentation, items that do not line up, a repeated key or a missing space after a colon.

No. JSON has no comments, so they are dropped.

They are ignored and the value is kept as plain data. A note under the result lists the tags that were found, so you know to check them.

No. The conversion runs in your browser and nothing is sent to a server.