DevSwitch.net
Back to Tools
⇄

JSON to YAML Converter

Convert JSON data to YAML format

File Converters

Tip: YAML is more human-readable than JSON with cleaner syntax and no braces.

Runs in your browser

Input JSON

Convert JSON to YAML in your browser

Paste JSON, open a .json file or drop it on the input window, and the YAML appears as you type. Braces and brackets give way to indentation, objects become key-value blocks and arrays become lists of - items. Copy the result or download it as a .yaml file.

The YAML is written by js-yaml with two-space indentation, the style used in Kubernetes manifests, Docker Compose files and CI pipelines. Every value keeps its type: a JSON string stays a string, a number a number.

JSON to YAML example

Real output for two user records. The ZIP code "0150" keeps its quotes, "1100-148" does not need them:

users.json
[
  {"id": 101, "name": "Ivo Marsh", "address": {"city": "Lisbon", "zip": "1100-148"}, "tags": ["admin", "beta"]},
  {"id": 102, "name": "Lena Fisk", "address": {"city": "Oslo", "zip": "0150"}, "tags": ["beta"]}
]
users.yaml
- id: 101
  name: Ivo Marsh
  address:
    city: Lisbon
    zip: 1100-148
  tags:
    - admin
    - beta
- id: 102
  name: Lena Fisk
  address:
    city: Oslo
    zip: '0150'
  tags:
    - beta

Which strings stay in quotes

YAML drops most quotes. It keeps them where an unquoted string would be read as something else:

  • JSON

    "0150", "4.50", "123"

    YAML

    Stay '0150', '4.50' and '123'. Unquoted they would load as numbers.

  • JSON

    "true", "null", "yes", "on"

    YAML

    Stay quoted, so no YAML reader turns them into a boolean or null. Older YAML 1.1 readers treat yes and on as true.

  • JSON

    "- x", "#tag", "a: b"

    YAML

    Stay quoted, because a dash or a hash at the start, or a colon followed by a space, is YAML syntax.

  • JSON

    "Lisbon", "nginx:1.27"

    YAML

    Lose their quotes: nothing in them can be misread, so YAML writes them plain.

Lists, empty values and long text

How they are written

  • An array becomes a list with one - per item; an array inside an array becomes - - 1
  • [] and {} stay as they are, and null stays null
  • A string with \n in it becomes a |- block, one line of text per line
  • Long strings stay on one line and are never folded

Not done

  • Add comments: JSON has none to carry over
  • Use anchors and aliases for repeated blocks: each one is written out in full
  • Put several documents in one file with ---

Need the JSON back?

The YAML to JSON converter reads a YAML file back into indented JSON, with numbers, booleans and null typed.

JSON to YAML questions

Click Open file and pick the .json, or drop the file on the input window. It is read in your browser and converted straight away; Download saves the result as a .yaml file.

It is a string in your JSON. Without quotes a YAML reader would load it as a number and drop the zero, so the quotes keep your data as it was.

Mostly yes: YAML 1.2 was designed so that JSON documents are valid YAML. Converting is still worth it for files people edit, because indented YAML has no braces, commas or quotes to keep balanced.

The output window shows the parser's message with the position of the problem, and the YAML updates as soon as the JSON is valid. The JSON beautifier helps to find the mistake.

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