OnlineTextLab
Esc

YAML to JSON Converter

Resolves anchors and merge keys so you can see the data your YAML really means, with indentation errors pinpointed.

JSON output

Your JSON appears here as you type.

Nothing to paste yet? Use Try an example to see it work.

Options
Indent

Runs on your device. Your files and text are not uploaded.

About YAML to JSON

YAML saves typing and hides mistakes. A misplaced space changes the structure, an anchor pulls in values from elsewhere, and a bare no means different things to different parsers. Converting to JSON shows you the data as a program sees it, with nothing implied.

People reach for this while debugging Docker Compose files, Kubernetes manifests and CI configuration, or when an API or tool needs JSON and the source of truth is YAML.

The output is plain JSON with all aliases expanded and all block text resolved. If the YAML is invalid, you get the line, the column and what to change.

How it works

The parser follows YAML 1.2. It handles block and flow collections, plain and quoted scalars with their escapes, | and > block text with chomping and indent indicators, comments, tags, and several documents in one stream. Lists written at the same indent as their key, the style common in Kubernetes files, read correctly.

Anchors and aliases are expanded, and << merge keys are applied with the usual rule: a key written in the mapping itself beats a merged one. Merge keys come from YAML 1.1 but remain widespread, so they are supported. If aliases would expand to more than two million values, the conversion stops with an error, which protects your browser tab from a billion laughs document.

Some values are deliberately left as text to avoid changing them: 007 keeps its zeros, a very long integer keeps its digits, and .inf stays a string because JSON has no way to write it. You get a notice for the cases that could surprise you.

How to use YAML to JSON

  1. Paste YAML into the input, or open a .yaml or .yml file.
  2. Read the JSON on the right to see exactly how your indentation and aliases resolved.
  3. If a notice mentions yes, no or a tag, check that the value came out as you intended.
  4. Grab the result using Copy or Download .json.

An anchor, a merge key and a block of text

Input
defaults: &defaults
  restart: always
  logging: json
worker:
  <<: *defaults
  restart: on-failure
  command: |
    migrate
    serve
Output
{
  "defaults": {
    "restart": "always",
    "logging": "json"
  },
  "worker": {
    "restart": "on-failure",
    "logging": "json",
    "command": "migrate\nserve\n"
  }
}

worker picked up logging from the anchor while its own restart won over the merged one. The | kept the line break in command and added one trailing newline, which is what plain | means.

When it helps

  • Seeing the final settings of a Compose service after its anchors and merges are applied.
  • Tracking down why a Kubernetes manifest is rejected, since a stray indent shows up as an error or a misplaced key.
  • Sending configuration kept in YAML to an API that takes JSON.
  • Checking whether a multi-line command will keep or lose its line breaks.

Tips for a better result

  • Quote anything that looks like a number or boolean but is not one, such as version strings like "1.10". Unquoted, 1.10 is the number 1.1.
  • Choose | for text whose line breaks matter and > for prose that should fold into one line. Add - to either one to drop the final newline.
  • When a file holds several documents separated by ---, the output is a list with one entry per document. A notice tells you this has happened.

Good to know

  • Keys must be plain text. The ? syntax for complex keys, and lists or maps used as keys, produce an error.
  • Custom tags such as CloudFormation's !Ref are dropped with a notice and the value kept, so the output will not carry their meaning.
  • Comments are not carried over, because JSON has nowhere to put them.
  • Timestamps stay as strings, since JSON has no date type.

Questions people ask

Why did the word no stay as text instead of becoming false?

YAML 1.2 made only true and false booleans. Older YAML 1.1 parsers also read yes, no, on and off that way, which is how the country code for Norway once turned into false. A notice appears when one of these words is found, so you can decide.

What does the error about a line being indented further mean?

The line sits deeper than the key above it but cannot belong to that key, usually because the key already has a value on its own line. Line it up with its siblings, or quote the value if it was meant to continue.

Are duplicate keys allowed?

The YAML specification requires keys to be unique, so a repeat is reported with its line and column. Some parsers silently keep the last one, which is how settings get lost.

Does it read tabs in indentation?

No. YAML forbids tabs for indentation, and the error shows where the tab is. Tabs are fine elsewhere, such as between a value and a comment.

What to use next

Learn more

Last reviewed . Read our editorial policy.