Skip to main content

YAML to JSON

Convert YAML to JSON, with anchors and documents.

YAML input

Ln 1, Col 1
YAML

Result

Your result will appear here

Add YAML above, then choose Convert.

Add YAML on the left, then choose Convert.

Waiting for input

2 spaces

Convert YAML to JSON with anchors and aliases resolved. A file with several documents becomes a JSON array.

What is YAML to JSON?

YAML to JSON is a free online tool that converts YAML into JSON in your browser. It reads YAML under the YAML 1.2 Core rules, turns anchors and aliases into plain values, and writes a file with several documents as a JSON list.

It either converts every value or refuses and tells you why, for example for a number that JSON cannot write.

What it supports

  • YAML read under the YAML 1.2 Core rules, as one document or several separated by ---: plain, quoted and multi-line text, numbers, true, false, null, lists, mappings, comments, anchors and aliases.
  • Keys must be text. They are written in the order they appear, and values that are numbers, true, false and null keep their JSON types.
  • Numbers keep their digits when they are already valid in JSON: 12345678901234567890, 1e3 and 1.50 are written as they are. Hexadecimal and octal numbers and numbers with a leading plus or leading zeros (0x1F, 0o17, +12, 007) are written as plain decimal numbers, and .5 becomes 0.5.
  • Anchors and aliases are resolved: each alias becomes a full copy of its anchored value, and an anchor applies to the aliases that follow it in its own document.
  • Several documents become a JSON list with one item per document, and an empty document between two --- lines becomes null. A single document is written as itself.
  • Block text (| and >), quoted escapes such as \t and multi-line plain text become ordinary JSON text with the line breaks YAML defines.
  • The merge key << is read as an ordinary key, with a warning, because YAML 1.2 Core has no merge keys. yes, no, on and off are plain text.

Good to know

  • Refused instead of changed: infinity and NaN (.inf, -.inf, .nan), an alias that points to a value that contains it (a cycle), a key that is not text (a number, true, false, null, or a list or mapping used as a key), a custom or non-Core tag, and a directive such as %YAML.
  • JSON keeps no comments, anchors or document markers, and every alias becomes a copy, so the JSON can be much bigger than the YAML. A document that grows past the size limit is refused rather than cut.
  • Programs that follow the older YAML 1.1 rules read some values differently, for example yes and no as booleans or 010 as an octal number. This tool follows YAML 1.2, so check those values if your program uses YAML 1.1.
  • A key repeated in the same mapping, an alias with no anchor and a syntax error are refused with the line and column of the problem.
  • A document with only comments has nothing to convert, so you get a note asking for content.

How do I use YAML to JSON?

  1. Paste or type your YAML in the input box. Nothing runs while you type.
  2. Choose the indentation (“2 spaces” or “4 spaces”) and press “Convert”.
  3. Read the JSON next to your input. If the conversion is refused, the message says why and gives the line and column.
  4. Press “Copy” to put the JSON on your clipboard, or “Download” to save it as converted.json.

Examples

A mapping and a list

Paste this YAML and press “Convert”. The keys become JSON names, 8080 and false stay a number and a boolean, the lines that start with a dash become a list, and the comment is left out because JSON has no comments.

name: demo
port: 8080
debug: false
# not kept in JSON
tags:
  - api
  - web
{
  "name": "demo",
  "port": 8080,
  "debug": false,
  "tags": [
    "api",
    "web"
  ]
}

A value JSON cannot hold

.inf is infinity, a number in YAML, but JSON has no way to write it, so the conversion is refused instead of changing the value. The same goes for -.inf and .nan. The message gives the line and column of the value.

limit: .inf

This value (.inf, -.inf or .nan) is a number that JSON cannot represent. JSON has no infinity and no NaN, so the conversion was refused instead of changing your data. Replace it with a finite number or a quoted string.

Line 1, column 8

Anchors and aliases

The alias *d is replaced by a copy of the value that the anchor &d marks, so prod gets the same retries as defaults. JSON has no aliases, so every use becomes its own copy.

defaults: &d
  retries: 3
prod: *d
{
  "defaults": {
    "retries": 3
  },
  "prod": {
    "retries": 3
  }
}

Several documents

A line with --- starts a new document. Two documents become a JSON list with one item for each, while a file with a single document is written as that document, not as a list of one.

---
name: web
---
name: api
[
  {
    "name": "web"
  },
  {
    "name": "api"
  }
]

Words and numbers that look like something else

The tool reads YAML 1.2 Core, where yes is plain text and stays “yes”. 0x1F is a hexadecimal number, written as 31, and 007 is the number 7. A long whole number such as 12345678901234567890 keeps every digit.

enabled: yes
port: 0x1F
zip: 007
id: 12345678901234567890
{
  "enabled": "yes",
  "port": 31,
  "zip": 7,
  "id": 12345678901234567890
}

Limits and privacy

Size limits

  • Input: up to 2,000,000 bytes of UTF-8 text (about 2 MB). Accented letters and emoji take more than one byte each. Larger input is rejected.
  • Result: also up to 2,000,000 bytes. If the complete result would be larger, the tool shows only an incomplete preview of the first 100,000 bytes, and that preview cannot be copied or downloaded.
  • Nesting: up to 256 levels of mappings and lists inside each other. Deeper YAML is refused because it is beyond what the tool processes.
  • Time: a run that takes longer than its time limit is stopped. Try a smaller input.

Is my text sent to a server?

No. The text you type or paste, or open from a local file, is processed locally in your browser, in a dedicated Web Worker. It is never uploaded or sent to the server (a file you open is read in your browser only), and it is not written to storage, cookies or the address bar.

“Copy” puts the result on your clipboard and “Download” saves it as a file, but only when you press the button. The file is created in your browser, so nothing is uploaded.

For the full details, see the Privacy Policy

Related tools and pages

Your text stays in the page when you switch tools in the same tab, so you can try the same text in another tool. Reloading or closing the tab ends it.

All tools