DevSwitch.net
Back to Tools
⇄

YAML to JSON Converter

Convert YAML data to JSON format

File Converters

Tip: Paste your YAML data. It will be converted to properly formatted JSON.

Runs in your browser

Input YAML

Convert YAML to JSON in your browser

Paste YAML, open a .yaml or .yml file or drop it on the input window, and the JSON appears as you type. Mappings become objects, lists become arrays, and the result is indented with two spaces. Copy it or download it as a .json file.

The YAML is read by js-yaml with the YAML 1.2 rules. A wrong indent, a tab used for indenting or a key written twice shows the error in the output window, with the line and column and a marker at the spot.

YAML to JSON example

Real output for a config with two services. Ports and replicas stay numbers, and a key that only one item has appears only in that object:

services.yaml
- name: api
  image: nginx:1.27
  ports:
    - 8080
    - 8443
  env:
    LOG_LEVEL: info
- name: worker
  image: node:22
  replicas: 3
  env:
    LOG_LEVEL: debug
services.json
[
  {
    "name": "api",
    "image": "nginx:1.27",
    "ports": [
      8080,
      8443
    ],
    "env": {
      "LOG_LEVEL": "info"
    }
  },
  {
    "name": "worker",
    "image": "node:22",
    "replicas": 3,
    "env": {
      "LOG_LEVEL": "debug"
    }
  }
]

How YAML values become JSON types

Unlike CSV or XML, YAML has types, and the JSON keeps them:

  • YAML

    8080, 1.5, 0o17

    JSON

    Become JSON numbers. 0o17 is octal and becomes 15.

  • YAML

    true, false, null, ~

    JSON

    Become true, false and null.

  • YAML

    yes, no, on, off

    JSON

    Stay strings. YAML 1.2 no longer reads them as booleans, so they are not turned into true or false.

  • YAML

    2024-01-05

    JSON

    Stays the date as written, "2024-01-05", since JSON has no date type. A date with a time becomes an ISO timestamp in UTC, such as "2024-01-05T10:20:00.000Z".

  • YAML

    | and > blocks

    JSON

    Become one string. A literal block keeps its line breaks as \n; a folded block joins its lines with spaces.

What JSON cannot hold

Resolved

  • Anchors and aliases: each *alias is replaced by a full copy of the anchored value
  • Flow style such as [1, 2] and {a: 1}, read like the block style
  • Quoted values, which always stay strings: '007' keeps its zeros

Dropped or refused

  • Comments: JSON has no comments, so they are left out
  • Anchor names: only the copied values remain
  • A second document after ---: the converter reads one document and shows an error for more

Need the YAML back?

The JSON to YAML converter writes JSON as block-style YAML with two-space indentation.

YAML to JSON questions

Click Open file and choose the .yaml or .yml file, or drop it on the input window. Both extensions hold the same format. Download saves the result as a .json file.

Not in one go. A Kubernetes file with several manifests separated by --- shows an error; paste one document at a time.

JSON has no syntax for comments, so there is nowhere to put them. Keep the YAML as your source file if the comments matter.

Use a JSON Schema validator in your project; JSON Schema validation explains how. To re-indent or check JSON from elsewhere, use the JSON beautifier.

No. Converting runs in your browser, and an opened file is read there too.