YAML to JSON

Convert YAML to JSON instantly in your browser.

Local Your input is processed locally in your browser. The first run loads the open-source js-yaml library from this site; your input is not sent anywhere. Found a problem? Report an issue

What YAML to JSON does

YAML to JSON reads YAML and writes it as JSON. The input is parsed first, so a syntax error is reported with its position instead of producing broken output.

YAML to JSON examples

The built-in sample

Input

name: Ada
tags:
  - math
  - code
address:
  city: London

Output

{
  "name": "Ada",
  "tags": [
    "math",
    "code"
  ],
  "address": {
    "city": "London"
  }
}

This is the input that the Load sample button fills in.

How YAML values are typed

Input

version: 1.10
enabled: yes
released: 2024-01-05
base: &b
  retries: 3
prod: *b
host: ~
# trailing comment

Output

{
  "version": 1.1,
  "enabled": "yes",
  "released": "2024-01-05T00:00:00.000Z",
  "base": {
    "retries": 3
  },
  "prod": {
    "retries": 3
  },
  "host": null
}

1.10 is a number, so it becomes 1.1. The word yes stays a string, the unquoted date becomes an ISO 8601 timestamp, the alias *b is replaced by a copy of the anchored mapping, ~ becomes null and the comment disappears.

Each output was produced by running this tool on the input above it.

How it works

Reading YAML. The input is parsed with js-yaml. Values keep the types YAML assigns them (numbers, booleans, null and timestamps), anchors and aliases are expanded into full copies, and comments are dropped.

Writing JSON. The result is written as JSON with two-space indentation.

Details and limits

  • There is no fixed size limit: everything runs on your device, so very large inputs depend on its memory.
  • It works in current browsers on phones, tablets and computers, and it is free with no account needed.
  • Values are carried across without losing anything in ordinary data; the points above list the cases the two formats handle differently.
  • A YAML file with several documents separated by --- is rejected with "expected a single document". Convert one document at a time.
  • Mapping keys must be strings in JSON. A numeric YAML key such as 404: becomes the string key "404".
  • Special floats (.inf, .nan) have no JSON form and are written as null.
  • Input that is not valid YAML stops the tool, and the status line shows where the problem is. The YAML Validator page lists the usual causes.

Questions

Why did 1.10 become 1.1?

Without quotes, YAML reads 1.10 as a number, and the number has no trailing zero. Write "1.10" in the YAML if it is a version string.