YAML to JSON Converter

Convert YAML, including anchors, multi-line strings and multi-document files, into formatted JSON.

Overview

YAML is pleasant to write but hard to reason about: indentation carries meaning, unquoted values change type depending on how they look, and anchors can pull data in from elsewhere in the file. Converting to JSON shows you exactly what a program will receive after parsing, which makes it the fastest way to debug a Kubernetes manifest, a CI pipeline or an application config that does not behave the way it reads.

This tool parses YAML 1.2 with js-yaml in your browser, without uploading anything. Errors are reported with the line and column where the parser stopped, files with several ----separated documents become a JSON array, and options let you emulate YAML 1.1 booleans or resolve AWS CloudFormation short-form tags.

How to convert YAML to JSON

  1. Paste YAML into the left pane or open a .yaml / .yml file. The JSON updates as you type.
  2. If the status bar shows an error, go to the reported line and column. Tabs in indentation, a missing space after a colon and inconsistent indentation are the usual causes.
  3. Choose a 2-space, 4-space or tab indent, then copy the JSON or download it.
  4. Enable YAML 1.1 booleans to see how an older parser such as PyYAML would read yes, no, on and off.
  5. Enable CloudFormation tags for templates that use !Ref, !Sub or !GetAtt; they become {"Ref": ...} and {"Fn::Sub": ...}.

Anchors, aliases and merge keys

An anchor (&name) labels a node, an alias (*name) reuses it, and the merge key << copies a mapping's keys into another mapping. Keys you write explicitly win over merged ones:

defaults: &defaults
  adapter: postgres
  pool: 5
production:
  <<: *defaults
  pool: 20
{
  "defaults": { "adapter": "postgres", "pool": 5 },
  "production": { "adapter": "postgres", "pool": 20 }
}

JSON has no references, so every alias is expanded into a full copy. A small file that aliases a large block many times can therefore produce much larger JSON. The merge key comes from YAML 1.1 and is not part of the YAML 1.2 core schema, but js-yaml and most other parsers still support it.

Multi-line strings: | versus >

A literal block (|) keeps line breaks exactly, which is what you want for scripts and certificates. A folded block (>) joins lines with spaces, which suits long prose. The chomping indicator controls the final newline: by default one is kept, - strips it and + keeps all trailing blank lines.

script: |        →  "npm ci\nnpm test\n"
  npm ci
  npm test
message: >-      →  "Deploys the web tier"
  Deploys the
  web tier

The Norway problem: YAML 1.1 versus 1.2

Under YAML 1.1, a list of country codes like [se, no, dk] loads as ["se", false, "dk"], because no is a boolean. YAML 1.2 (2009) fixed this: its core schema only treats true and false as booleans. js-yaml follows 1.2, and these are the results this page actually produces:

YAML valueThis tool (YAML 1.2)YAML 1.1 parser
no, off, n"no", "off", "n"false
yes, on, ystringstrue
True, TRUEtruetrue
010108 (octal)
0o108"0o10"
~, empty valuenullnull

The YAML 1.1 booleans option switches the first two rows to the 1.1 behaviour; it does not change how numbers are read. Many tools still use 1.1 rules, PyYAML among them, so the safe habit is to quote any string that could be mistaken for something else. The YAML 1.2.2 specification has the full core schema.

Common errors and multi-document files

  • tab characters must not be used in indentation: YAML forbids tabs for indentation. Replace them with spaces.
  • duplicated mapping key: the same key appears twice in one mapping. Many parsers silently keep the last value; js-yaml refuses, which catches real mistakes in long config files.
  • bad indentation of a mapping entry: often key: value: more on one line, or a child indented less than its siblings. Quote values that contain ": ".
  • unknown tag !<!Ref>: a custom tag. Enable CloudFormation tags, or remove the tag.

Files such as kubectl output or Helm templates often contain several documents separated by ---. They are loaded with loadAll and returned as a JSON array with one element per document; empty documents, such as one after a trailing ---, are skipped and the status bar says so. To go the other way, use the JSON to YAML converter, or tidy the source with the YAML formatter and inspect the result in the JSON viewer.

Frequently Asked Questions

Are YAML comments kept in the JSON?

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

Why does "no" stay a string here when my Python app reads it as false?

This tool follows YAML 1.2, where only true and false are booleans. PyYAML implements YAML 1.1. Tick "YAML 1.1 booleans" to preview the 1.1 result, and quote the value in your file to make it unambiguous.

What happens to dates and timestamps?

Unquoted values like 2024-01-15 are YAML timestamps. JSON has no date type, so they are written as ISO 8601 strings in UTC, for example "2024-01-15T00:00:00.000Z". Quote dates in the YAML to keep the original text.

Is my YAML sent to a server?

No. The conversion runs entirely in your browser. Your last input is saved in local storage so it is still there after a refresh.

Why is the JSON output an array when my YAML is a single object?

Your file contains more than one document separated by ---. Each document becomes one array element. Remove the extra separators if you meant a single document.