Skip to content
PC Moment

Free tool

YAML to JSON Converter (and JSON to YAML)

Paste YAML to get JSON, or JSON to get YAML. Errors show the line and column, and nothing you paste leaves your browser.

Direction

YAML is easy to write by hand, which is why it shows up in config files, CI pipelines and container setups, but many programs and APIs want JSON instead. This converter turns YAML into JSON, or JSON back into YAML, using a YAML 1.2 parser that runs inside the page. When the YAML doesn’t parse, it shows the parser’s message with the line and column, so you can find the problem quickly.

How to use the YAML to JSON converter

  1. Choose the direction: YAML → JSON or JSON → YAML.
  2. Paste your YAML (or JSON) into the text box.
  3. Pick the indent for the output: 2 spaces or 4 spaces.
  4. Select Convert.
  5. Read the status line: a confirmation that the input was valid, or the parser’s error message with the line and column where it stopped.
  6. Use Copy to put the result on your clipboard, or Download to save it as a .json file (YAML → JSON) or a .yaml file (JSON → YAML).

How it works

In the YAML → JSON direction, the tool parses your text with the open-source yaml library for JavaScript. The library reads YAML 1.2 by default with the core schema, which the YAML 1.2.2 specification calls the recommended default schema. The result is then written out as JSON with the indent you chose. Along the way:

  • Comments are dropped. The YAML spec says comments are a presentation detail and must not affect the data, and JSON has no comment syntax at all (RFC 8259 allows only whitespace between tokens).
  • Anchors and aliases are resolved. An anchor (&name) labels a value and an alias (*name) reuses it. In the JSON, each alias is replaced by a full copy of the anchored value, and the anchor names disappear: the spec says they are discarded once the document is loaded.
  • Several documents become an array. A YAML file can hold more than one document, separated by --- lines. If yours does, the JSON output is an array with one item per document, and the status line says how many documents it found. A single document converts to that document’s value on its own.
  • Errors come from the parser. If the YAML is invalid, the status line shows Invalid YAML (line N, column N) followed by the library’s message, for example “Tabs are not allowed as indentation”.

In the JSON → YAML direction, the tool reads your input with the browser’s strict JSON parser, so it has to be valid JSON (no comments, no trailing commas). It then writes YAML with the yaml library. Strings that YAML would otherwise read as numbers, such as "01234", are written with quotes so they stay text.

yes, no, on and off are strings in YAML 1.2

This is the difference between YAML versions that catches people out most. In YAML 1.1, the boolean type matched 22 spellings, including y, yes, no, on and off in several capitalizations. YAML 1.2’s core schema matches only six: true, True, TRUE, false, False and FALSE. Everything else is a string.

YAML valueYAML 1.1 parserThis converter (YAML 1.2)
enabled: yestrue"yes"
debug: offfalse"off"
country: NOfalse"NO"
verified: truetruetrue

The country: NO row is the classic case: under YAML 1.1 the country code for Norway turns into false. If you need a real boolean in YAML 1.2, write true or false.

Note: In the other direction the converter plays it safe. Converting {"answer": "yes"} from JSON gives answer: "yes" with quotes, so the value stays a string even in older software that follows YAML 1.1. Real JSON booleans are written as plain true and false.

Worked examples

A config file with comments (2 spaces). This YAML:

server:        # web server settings
  host: localhost
  port: 8080   # default port
  tls: false
paths:
  - /var/www
  - /srv/static

becomes:

{
  "server": {
    "host": "localhost",
    "port": 8080,
    "tls": false
  },
  "paths": [
    "/var/www",
    "/srv/static"
  ]
}

Both comments are gone, 8080 is a number and false is a boolean.

Booleans and a version number. This YAML:

enabled: yes
debug: off
country: NO
verified: true
version: 1.10

becomes:

{
  "enabled": "yes",
  "debug": "off",
  "country": "NO",
  "verified": true,
  "version": 1.1
}

Only verified is a boolean. The unquoted 1.10 is read as a number and comes out as 1.1; write version: "1.10" to keep it as text.

Anchors and aliases. This YAML defines base once and reuses it:

base: &base
  image: nginx
  port: 80
web: *base

In the JSON, web gets its own full copy:

{
  "base": {
    "image": "nginx",
    "port": 80
  },
  "web": {
    "image": "nginx",
    "port": 80
  }
}

Two documents in one file. This YAML:

---
name: web
replicas: 2
---
name: worker
replicas: 1

becomes a JSON array, and the status line reads “Valid YAML: 2 documents, converted to a JSON array.”:

[
  {
    "name": "web",
    "replicas": 2
  },
  {
    "name": "worker",
    "replicas": 1
  }
]

A tab in the indentation. YAML only allows spaces for indentation. If the second line of a file starts with a tab, as in server: followed by a tab and host: localhost, the status line shows:

Invalid YAML (line 2, column 1): Tabs are not allowed as indentation

Replace the tab with spaces and it converts.

JSON to YAML. With JSON → YAML and 2 spaces, this JSON:

{"name":"Ada","languages":["en","fr"],"active":true,"id":7}

becomes:

name: Ada
languages:
  - en
  - fr
active: true
id: 7

Frequently asked questions

Is my YAML sent to a server?

No. The YAML parser is part of the page, so the conversion runs in your browser and the text you paste never leaves your device.

Why did yes become a string instead of true?

The converter follows YAML 1.2, whose core schema only treats true and false (in lowercase, capitalized or all caps) as booleans. Words like yes, no, on and off were booleans in YAML 1.1, but in YAML 1.2 they are plain strings.

What happens to my comments?

They are dropped. The YAML spec treats comments as presentation details that don't belong to the data, and JSON has no comment syntax, so there is nowhere to put them.

Can I convert a file with several YAML documents?

Yes. Documents separated by --- become one JSON array, with one item per document in the same order. The status line tells you how many documents it found.

Why did my version number 1.10 turn into 1.1?

An unquoted 1.10 is a number in YAML, and as a number it equals 1.1. Put quotes around values like versions, ZIP codes and phone numbers ("1.10") to keep them as text.

Is JSON valid YAML?

For practical purposes, yes. The main goal of YAML 1.2 was to make YAML a strict superset of JSON, so a JSON document can be read by a YAML 1.2 parser. The JSON to YAML direction uses the browser's strict JSON parser, though, so the input has to be valid JSON.

Related guides

PC Moment title card for JSON Formatter

Free tool

JSON Formatter and Validator

Paste JSON to pretty-print or minify it, sort the keys and find syntax errors by line and column. Everything runs in your browser.

Free calculator

Free Developer and PC Tools

Free formatters, decoders and converters for developers and PC users. Everything runs in your browser, and nothing you type is sent anywhere.

3 min read