YAML to JSON Converter

Paste YAML to get JSON, or switch direction to turn JSON into YAML. Anchors, merge keys and multi-document files are handled, and syntax errors point to the exact line.

100% freeNo sign-upRuns in your browserWorks on mobile
Converts as you type. Nothing is uploaded.
Indentation

How to use the YAML to JSON Converter

  1. Pick the direction: YAML → JSON or JSON → YAML.
  2. Paste your data, open a .yaml, .yml or .json file (the direction is chosen from the file), or click Load sample.
  3. Set the indentation. For YAML input choose YAML 1.2 or 1.1 rules; for YAML output you can sort keys or fold long text.
  4. If an error appears, click Go to line to fix it, then copy or download the result. Swap sends the output back as new input.

Features

  • Two-way conversion: YAML to JSON and JSON to YAML
  • Anchors, aliases and << merge keys resolved
  • Multi-document YAML combined into a JSON array
  • YAML 1.2 or YAML 1.1 rules for yes and no
  • Errors with line, column and the offending line
  • Sorted keys and line folding for YAML output

Same data, two notations

YAML and JSON describe the same kinds of data: objects (called mappings in YAML), lists (sequences) and plain values such as strings, numbers, booleans and null. JSON uses braces, brackets and quotes, which makes it strict and easy for programs to exchange, so it dominates web APIs. YAML uses indentation and minimal punctuation, which makes it easier for people to write, so it dominates configuration: Kubernetes manifests, Docker Compose files, GitHub Actions workflows and Ansible playbooks are all YAML. YAML 1.2 was designed so that almost any JSON document is also valid YAML, which is why converting between them is reliable.

server:
  port: 8080
  hosts:
    - api.example.com
    - www.example.com

is the same data as {"server": {"port": 8080, "hosts": ["api.example.com", "www.example.com"]}}.

What changes when you convert

  • Comments disappear. JSON has no comments, so lines starting with # cannot be carried over.
  • Anchors are expanded. A block defined once with &defaults and reused with *defaults or merged with <<: *defaults is copied into every place that uses it.
  • Several documents become one array. A file split with --- lines turns into a JSON array with one item per document.
  • Key order is kept, unless you choose to sort keys when producing YAML.
  • Special values. YAML’s .nan and .inf have no JSON equivalent and become null, and binary data becomes a Base64 string.

The yes and no problem

The older YAML 1.1 specification treats many words as booleans: yes, no, on, off, y and n, in any capitalization. That surprises people: a list of country codes containing NO for Norway turns into false, and a key called on becomes true. YAML 1.2 fixed this, so only true and false are booleans. This converter uses YAML 1.2 by default; switch to YAML 1.1 rules to see how a tool built on an older library, such as PyYAML, will read your file. Either way, quoting values like "no" removes all doubt.

Common YAML errors

ErrorCause and fix
Bad indentation of a mapping entryA key is indented more or less than its siblings. Line keys up with spaces.
Tab charactersYAML does not allow tabs for indentation. Replace them with spaces.
Duplicated mapping keyThe same key appears twice in one mapping. Remove or rename one.
Missing space after a colonkey:value is read as one string. Write key: value.
Unexpected characters at the start of a valueValues starting with @, `, *, & or ! have special meanings. Put them in quotes.

Error messages give the line and column where the parser stopped, and Go to line jumps straight there. To tidy JSON afterwards, use the JSON Formatter; to compare two versions of a config file, use Text Compare.

Frequently asked questions

Are YAML comments preserved?

Not when converting to JSON, because JSON has no comment syntax. Converting JSON to YAML produces a file without comments, which you can then annotate.

Why did "yes" turn into true?

You have YAML 1.1 rules selected, which treat yes, no, on and off as booleans. With the default YAML 1.2 rules they stay strings. Quote such values to make your file safe under both versions.

How are anchors and aliases handled?

They are resolved. Every alias is replaced by a copy of the anchored value, and merge keys (<<) copy the anchored mapping’s keys into the current mapping, with local keys taking priority.

Can it convert a file with several YAML documents?

Yes. Documents separated by --- lines are combined into a JSON array, with one element per document, in order.

Is my data sent to a server?

No. Parsing and conversion happen in your browser, so configuration files containing hostnames or secrets stay on your device.

More developer tools

Other free tools you might need next.

View all 24