Formatters

Convert YAML to JSON

YAML to JSON converter parses the YAML you paste with the js-yaml parser and prints it as JSON, indented four spaces per nesting level by default ("Indent" also offers 2 spaces or a tab). Developers use it to read CI configuration, docker-compose files and Kubernetes manifest snippets as JSON, and to hand YAML-written config to tools that only accept JSON. Anchors and aliases resolve to their full values, YAML numbers such as 1.0 serialize as 1, unquoted date-like scalars become UTC timestamp strings, and a file with several --- documents becomes a JSON array.

How to use YAML to JSON

  1. Open YAML to JSON in the Toolbox101 app.
  2. Paste the YAML into the YAML box; a config block or manifest snippet works.
  3. Pick Indent: 2 spaces, 4 spaces (the default) or Tab.
  4. Read the JSON in the Output box, with keys in document order. Aliases such as *base expand to their full value.
  5. Click Copy to put the JSON on your clipboard.

Worked example

YAML to JSON returns the output below for this input.

Input

name: toolbox101
version: 1.0
enabled: true
replicas: 3
ports:
  - 8080
  - 9090
env:
  NODE_ENV: production

Output

{
    "name": "toolbox101",
    "version": 1,
    "enabled": true,
    "replicas": 3,
    "ports": [
        8080,
        9090
    ],
    "env": {
        "NODE_ENV": "production"
    }
}

Check it yourself: open YAML to JSON and enter the same input.

Frequently asked questions

Are YAML anchors and aliases resolved?

Yes. An anchor such as &defaults and an alias such as *defaults are resolved while parsing, so the JSON repeats the anchored content at every alias instead of keeping the reference. Merge keys written with << are expanded the same way.

Why did my YAML value 1.0 become 1 in the JSON?

In YAML an unquoted 1.0 is a number, and JavaScript serializes the float 1.0 as 1 because JSON has no separate notation for a whole number. Quote the value, for example version: '1.0', if you need the string form preserved in the output.

Why did an unquoted date become a UTC timestamp string?

The js-yaml parser recognizes date-like scalars such as 2024-01-02 and converts them to UTC dates, so the JSON shows the ISO 8601 form ending in Z. Quote the value if you want the literal text kept instead of a parsed timestamp.

Can it convert a YAML file with multiple documents?

Yes. A stream with several documents separated by --- lines comes out as a JSON array with one element per document. A file with a single document is converted on its own, not wrapped in an array.

Use YAML to JSON now

Runs in your browser. Nothing you type is uploaded.