YAML to JSON Converter Online — Free, Paste or Upload .yml

Paste YAML or open a .yaml or .yml file, then convert YAML to JSON in your browser. The text stays on this page and is not uploaded.

YAML input

JSON output

Convert YAML to see JSON here.

What Is YAML to JSON Conversion?

This converter reads the editor with a YAML parseDocument step, using YAML 1.2 and the core schema. It then turns that document into a JavaScript value and writes JSON with JSON.stringify and two-space indentation. It converts one YAML document. The JSON is a new document, not a restyle of the YAML source.

Unquoted yes, no, on, and off stay strings. true and false become booleans. That is YAML 1.2, not YAML 1.1. The reverse direction is the JSON to YAML converter, which quotes "yes" when it writes YAML so tools that still follow YAML 1.1 are less likely to treat that word as a boolean.

Parsing, conversion, copy, and download all run in this browser. The YAML is not uploaded. A .yml file is YAML too. The download is converted-data.json.

How to Convert YAML to JSON

Step 1: Add YAML

Paste YAML into the editor, choose Open YAML File, or choose Load Sample YAML. Open YAML File converts as soon as a valid file is read. Load Sample YAML converts immediately.

Step 2: Convert pasted YAML

Pasted YAML needs Convert to JSON. Invalid YAML stays in the editor. The status line explains the problem, and the JSON preview is cleared.

Step 3: Read the JSON

The preview shows JSON with two-space indentation. Editing the YAML clears that preview until you convert again. Copy JSON and Download JSON need a current preview.

Step 4: Copy, download, or clear

Copy JSON copies the JSON already in the preview. Download JSON saves that same text as converted-data.json. Neither button converts again. If the preview is empty, both ask you to convert first. Clear empties both panels.

How This Converter Reads YAML

After a successful parse, the page writes pretty-printed JSON from the JavaScript value. It does not support every YAML feature. Custom tags, merge keys, binary data, and circular aliases are rejected instead of being rewritten into a different JSON value.

YAML 1.2 core schema

Unquoted yes, no, on, off, y, and n stay strings. true and false become JSON booleans. null, ~, and an empty value become JSON null. Quoted text stays text, so "01" does not become the number 1.

.yaml and .yml files

Open YAML File accepts .yaml and .yml. Both are read as YAML text. YML to JSON uses the same conversion as YAML to JSON.

Unique mapping keys

A mapping key cannot be repeated. If a key appears twice, conversion stops with YAML mapping keys must be unique. The last value is not kept.

Anchors, aliases, and expansion

An alias that simply repeats a value is written out in full in the JSON. The JSON does not keep YAML anchors. A circular alias is rejected. Merge keys such as << are not expanded.

JSON formatting and download

Successful output is JSON.stringify with two-space indentation. Download JSON saves converted-data.json.

YAML to JSON Examples

Nested values

name: Ada
active: true
score: null
tags:
  - yaml
  - json
address: {}
notes: []
{
  "name": "Ada",
  "active": true,
  "score": null,
  "tags": [
    "yaml",
    "json"
  ],
  "address": {},
  "notes": []
}

Words and quoted text

Unquoted yes and no stay strings. A quoted number-like value stays text, so "01" does not become the number 1.

flag: yes
other: no
code: "01"
{
  "flag": "yes",
  "other": "no",
  "code": "01"
}

A line break inside a string

message: |
  line1
  line2
{
  "message": "line1\nline2\n"
}

yes, on, and off versus true and false

In YAML 1.2, unquoted yes, on, and off stay strings. true and false become booleans.

flag: yes
power: on
mode: off
ok: true
stop: false
{
  "flag": "yes",
  "power": "on",
  "mode": "off",
  "ok": true,
  "stop": false
}

Quoted "01" versus unquoted 01

Unquoted 01 is a number. Quoted "01" stays a string.

plain: 01
quoted: "01"
{
  "plain": 1,
  "quoted": "01"
}

null, ~, and an empty value

All three become JSON null.

a: null
b: ~
c:
{
  "a": null,
  "b": null,
  "c": null
}

Anchors and aliases

The alias is expanded. The JSON contains the repeated value, not a YAML anchor.

city: &c Quetta
home: *c
work: *c
{
  "city": "Quetta",
  "home": "Quetta",
  "work": "Quetta"
}

Literal blocks | versus |-

| keeps a trailing newline. |- strips that final newline. The existing example above uses |, so the JSON string ends with a newline.

plain: |
  line1
  line2
stripped: |-
  line1
  line2
{
  "plain": "line1\nline2\n",
  "stripped": "line1\nline2"
}

A YAML sequence or string as the whole document

The root value does not have to be a mapping. A sequence, string, number, boolean, or null is converted. An unquoted yes as the whole document becomes a JSON string.

- Ada
- Ali
[
  "Ada",
  "Ali"
]
yes
"yes"

How Numbers and Keys Appear in the JSON

YAML is turned into a JavaScript value before JSON is written. JSON.stringify then prints that value. This is not JSON.parse. The JSON shows the number and key order JavaScript kept.

1.0 becomes 1

A trailing .0 is not kept in the JSON.

Input

small: 1.0
big: 9007199254740993

Output

{
  "small": 1,
  "big": 9007199254740992
}

Large integer precision

Integers outside ±9007199254740991 can change. 9007199254740993 is not preserved, as in the example above.

Negative zero becomes 0

YAML -0 is written as JSON 0.

Input

value: -0

Output

{
  "value": 0
}

Integer-like mapping keys

Keys that look like array indexes are written in numeric order, then the remaining keys. The names are not renamed. They appear as JSON strings.

Input

10: ten
2: two
name: Ada
1: one

Output

{
  "1": "one",
  "2": "two",
  "10": "ten",
  "name": "Ada"
}

Non-finite YAML numbers

.inf and .nan are rejected. The status line is This YAML cannot be converted to JSON. A value is not a finite JSON number.

Common Conversion Errors

Invalid YAML syntax

A broken mapping, a bad indent, or other syntax the parser rejects stays in the editor. The status line starts with Invalid YAML: and then includes the parser message. The preview is cleared.

Tab indentation

YAML indentation must use spaces. The second line below is indented with a tab. Status: Invalid YAML: Tabs are not allowed as indentation at line 2, column 1:

name: Ada
	city: Quetta

Misleading indentation

Some odd indents do not fail. They convert to a different value than the layout suggests. This input becomes one list item, not a nested list.

tags:
- yaml
  - json
{
  "tags": [
    "yaml - json"
  ]
}

Empty and comment-only input

An empty editor, whitespace-only text, or a comment with no document shows Paste YAML or open a .yaml or .yml file first. YAML null and ~ are values, and those become JSON null.

Empty uploaded file

A file whose size is 0 is not read. Status: This file is empty. Choose a YAML file with content. The editor and preview are left as they were.

Multiple YAML documents

Two documents separated by --- are rejected. A single --- at the start of one document is allowed. Status: Only one YAML document can be converted.

a: 1
---
b: 2

Duplicate mapping keys

Status: YAML mapping keys must be unique.

role: reader
role: admin

Unsupported merge keys

Status: This YAML cannot be converted to JSON. Merge keys are not expanded.

a: 1
<<: { b: 2 }

Unsupported custom tags

Status: This YAML cannot be converted to JSON. An unsupported tag was found.

value: !custom foo

Unsupported binary values

Status: This YAML cannot be converted to JSON. Binary data is not supported.

data: !!binary aGVsbG8=

Circular aliases

Status: This YAML cannot be converted to JSON. A circular alias was found.

&a
- *a

.inf and .nan

Status: This YAML cannot be converted to JSON. A value is not a finite JSON number.

File larger than 5 MiB

A YAML file larger than 5 MiB is rejected before it is read. Status: This file is larger than 5 MiB and was not read.

Pasted text longer than 5,000,000 characters

Pasted YAML longer than 5,000,000 characters is not converted. Status: This YAML is longer than 5,000,000 characters and was not converted. The editor is left as it was, and the preview is cleared.

Frequently Asked Questions

Why does the JSON preview disappear when I change the YAML?

Editing the YAML clears the JSON so the preview cannot stay out of date. Convert to JSON writes a new preview from the current editor. Copy JSON and Download JSON use that preview. They do not convert again.

Does Copy JSON convert again?

No. Copy JSON copies the JSON already in the preview. Download JSON saves that same text as converted-data.json. If the preview is empty, Copy JSON shows Convert YAML to JSON before copying. Download JSON shows Convert YAML to JSON before downloading.

Why does yes remain a string?

This converter uses YAML 1.2. An unquoted yes, no, on, or off is text. true and false are booleans. The JSON to YAML converter quotes "yes" when writing YAML, which is the other direction.

Can I open a .yml file?

Yes. Open YAML File accepts .yaml and .yml. Both are read as YAML text. The downloaded file is converted-data.json.

When should I use JSON to YAML instead?

Use the JSON to YAML converter when you already have JSON and need YAML, the JSON Beautifier to format JSON, or the JSON Viewer to inspect the tree.