JSON to YAML

Convert JSON data to YAML format instantly.

Any JSON: an object, a list, a single value, or JSON Lines (one value per line, each becoming a YAML document). Numbers are written exactly as they are in the JSON. Strings that a YAML reader would take for something else (yes, 22:22, 3.9, a date) are quoted.

Worth a look

Rate this tool

How useful was this tool?

JSON to YAML Converter

Paste or type JSON into the box, load the Example, or Open a file. The YAML appears as you type, ready to Copy or Download .yaml. Notes under Worth a look explain anything the converter had to decide, such as which strings it quoted and why.

The conversion runs in your browser. Nothing you paste or open leaves your computer.

Example

A service configuration in JSON:

{
  "services": {
    "web": {
      "image": "nginx:1.27",
      "ports": ["22:22"],
      "environment": {
        "DEBUG": "no",
        "COUNTRY": "NO",
        "PYTHON_VERSION": "3.10",
        "WORKERS": 4
      },
      "motd": "Welcome!nMaintenance on Sundays"
    }
  }
}

As YAML, with 2-space indent and quotes only where needed:

services:
  web:
    image: nginx:1.27
    ports:
      - "22:22"
    environment:
      DEBUG: "no"
      COUNTRY: "NO"
      PYTHON_VERSION: "3.10"
      WORKERS: 4
    motd: |-
      Welcome!
      Maintenance on Sundays

Four values are quoted, and each one has to be. Without quotes, many YAML readers would change them:

  • "22:22" would become the number 1342.
  • "no" and "NO" would become false.
  • "3.10" would become the number 3.1.

WORKERS stays a number because it’s a number in the JSON, and nginx:1.27 needs no quotes because nothing could misread it.

Why some strings need quotes

In JSON, quotes make it obvious what’s text. YAML lets you leave them out, and the reader guesses the type from how the value looks. Most tools still use YAML 1.1 rules for that guess, and those rules are surprisingly broad. Here’s what PyYAML does with these values when they aren’t quoted:

Text in your JSON Read by a YAML 1.1 parser as
yes, on true
no, off false
NO (Norway’s country code) false
22:22 1342 (a base-60 number)
3.10 3.1
1_000 1000
0777 511 (an octal number)
2024-01-15 a date, not text

 

These cause real bugs:

  • Docker Compose. Docker’s documentation tells you to quote port mappings, because 22:22 turns into 1342.
  • GitHub Actions. Workflows asking for python-version: 3.10 get Python 3.1.
  • Ansible. Its YAML reader treats yes and no as booleans.
  • Country lists. Lists of country codes lose Norway, because NO becomes false. That one has its own name: the Norway problem.

The converter quotes exactly the strings that would be misread and leaves everything else plain, so the YAML stays clean. A note lists each quoted string and the reason. Strings containing tabs or other control characters are written in double quotes with escape codes, the only safe way to write them in YAML.

If you’d rather not think about it at all, choose Quotes: Around every string.

Numbers stay as written

1.50 stays 1.50, and long IDs keep every digit, even beyond what JavaScript can store.

There’s one deliberate exception, explained in a note. A number written with an exponent, like 1e5, is written as 1.0e+5. YAML 1.1 only recognizes exponents with a decimal point and a sign, so a YAML 1.1 reader would take 1e5 for the text “1e5”. Both forms mean 100,000.

Multi-line strings

Text with line breaks is written as a | block by default, which keeps it readable:

motd: |-
  Welcome!
  Maintenance on Sundays

The character after | records how the text ends, so it converts back exactly:

  • |- means no line break at the end.
  • | means exactly one.
  • |+ means keep all the trailing line breaks.

The converter picks the right one. Choose In quotes, on one line to write such text as a single quoted line with n codes instead.

Options

  • Indent: 2 or 4 spaces. YAML doesn’t allow tabs for indentation.
  • Indent list items under their key: both styles are valid. Some teams indent list items under their key, while tools like kubectl write the dashes level with the key. Pick whichever matches your existing files.
  • Quotes: only where YAML needs them, or around every string.
  • Sort keys A to Z: handy for comparing two configurations.
  • Start with ---: adds the document marker at the top. Some tools and style guides expect it; most files work without it.

JSON Lines

Paste JSON Lines (one JSON value per line) and each line becomes its own YAML document, separated by ---. That’s the format kubectl apply and many other tools read when several resources share one file.

Unusual keys and duplicates

Keys follow the same quoting rules as values. A key called on or no is quoted, so it stays text. Keys longer than 1,024 characters are written in YAML’s explicit ? key form, because YAML doesn’t allow longer keys in the usual style.

Duplicate keys. If a key appears twice in the same JSON object, the YAML keeps the last value, which is what JSON readers do too, and a note tells you. Many YAML tools reject duplicate keys outright, so the output wouldn’t load anywhere if both were kept.

FAQ

What’s the difference between YAML 1.1 and 1.2?

YAML 1.2, from 2009, dropped most of the guessing: only true and false are booleans, and there are no base-60 numbers. But PyYAML, and many tools built on it or on older Go libraries, still follow 1.1. The converter writes YAML that reads the same under both versions.

Can I add comments?

JSON has no comments, so the YAML won’t have any either. You can add your own with # after converting.

Can I convert YAML back to JSON?

Yes, with YAML to JSON. If you paste YAML here by mistake, a note points you there.

My JSON has an error. Where is it?

The converter shows the line and column of the problem. For a full explanation of common mistakes, use the JSON Validator.

Is my data uploaded anywhere?

No. Everything happens in your browser, and nothing you paste or open is stored.

Note: All processing is done client-side. We do not store or see your data.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us