Skip to content
codevory

YAML to JSON Converter

Convert YAML to JSON, resolving anchors, aliases and merge keys. Big integers stay exact and key order is preserved.

YAML to JSON Converter: the tool

Paste YAML to convert it to JSON.

Input

JSON

The result appears here.

How to use YAML to JSON

  1. Paste YAML into the left panel, or press Example.
  2. Choose the JSON indentation, or Minified for the smallest output.
  3. Leave Expand merge keys on to apply <<: *anchor, as most YAML loaders do, or turn it off to keep the << key as it is.
  4. Copy the JSON or download it. If the YAML is invalid, the error shows the line and column.

Example

A small configuration with a comment, a list and a flow mapping. The comment has no JSON equivalent and is dropped.

YAML
# Service configuration
name: codevory
version: 1.0.0
server:
  host: localhost
  port: 8080
  tls: false
features:
  - json
  - yaml
  - xml
limits: {maxMb: 10, ratio: 0.5}
JSON
{
  "name": "codevory",
  "version": "1.0.0",
  "server": {
    "host": "localhost",
    "port": 8080,
    "tls": false
  },
  "features": [
    "json",
    "yaml",
    "xml"
  ],
  "limits": {
    "maxMb": 10,
    "ratio": 0.5
  }
}

About this tool

YAML 1.2 was designed as a superset of JSON, so the conversion works for almost any document, with a few details worth knowing. Anchors and aliases are resolved, so a value defined once and reused several times appears in full each time. Keys keep the order they have in the file, including keys that look like numbers.

Integers are written exactly, even beyond the 2^53 limit of JavaScript numbers, and hexadecimal (0x1F) and octal (0o17) numbers are written in decimal. Values that JSON cannot hold, .nan and .inf, become null and a warning says how many. Dates stay text, since YAML 1.2 does not turn them into a special type, and yes or no stay text rather than booleans.

A file with several documents separated by --- becomes a JSON array with one item per document. Documents that expand aliases an absurd number of times (an alias bomb) are refused rather than freezing the page.

Frequently asked questions

What happens to YAML comments?

They are dropped, because JSON has no comments. Use the YAML formatter if you need to keep them.

Are anchors and aliases resolved?

Yes. Every alias is replaced by the full value it refers to, so the JSON has no references. With Expand merge keys on, <<: *anchor also copies the anchored keys into the mapping.

Why are my dates strings in the JSON?

JSON has no date type, and YAML 1.2 keeps a value such as 2024-01-02 as text. If you need a timestamp, parse the string in your own code.

What if the YAML has several documents?

They are collected in a JSON array, one item per document, and a note tells you. A single document gives a single value.

Can every JSON document be read as YAML?

Almost always: YAML 1.2 was designed so that valid JSON is valid YAML. That means this tool also accepts JSON as input and gives it back reformatted.