JSON to YAML Converter

JSON Input
Settings
Options
YAML Output
Copied!

JSON is the format of APIs and web apps, but many tools expect configuration in YAML, such as Kubernetes, Docker Compose, GitHub Actions and OpenAPI files. The JSON to YAML Converter above turns JSON into clean, readable YAML. It quotes values that could be misread, keeps your key order and your exact numbers, and shows clear errors with the line and column. It runs in your browser, so your data is never uploaded.

Table of Contents

Why Convert JSON to YAML?

YAML is easier to read and edit by hand. It uses indentation instead of braces, allows comments, and handles multi-line text naturally. That is why many configuration tools use it. JSON is stricter and better for machines, so you often start with JSON from an API or a generator, and then need YAML for a config file.

YAML 1.2 was designed so that JSON is valid YAML, which means any JSON data can be written as YAML without losing information. The official rules are in the YAML 1.2.2 specification.

How to Use the JSON to YAML Converter

  1. Add your JSON. Paste it into the input box, or click Open File to load a .json file. Click Try Sample to see an example.
  2. Choose your settings. Set the indentation, quoting and list style.
  3. Check the result. The YAML updates as you type. If the JSON has a problem, a message shows the line and column with a pointer to the exact spot.
  4. Copy or download. Click Copy YAML or Download .yaml.

Settings Explained

Setting What it does Our advice
YAML indentation Sets 2 or 4 spaces per level. 2 spaces is the most common style.
Quote text values "Only when needed" keeps clean text plain. "Always" puts every text value in quotes. Use "Only when needed" for readable files.
Quote style Chooses single or double quotes when quotes are used. Text with line breaks or special characters always uses double quotes. Single quotes are simpler. Double quotes follow the JSON look.
Indent list items under their key Writes list items one level deeper than their key. Off writes them at the same level as the key. On is easier to read. Both are valid YAML.
Block style for multi-line text Writes text with line breaks using | instead of a long line with \n. Keep it on for readable text.
Sort keys alphabetically Sorts keys inside each object. Leave off to keep your original order.
Add document start (---) Adds a --- line at the top. Optional. Some tools expect it.

How Values Are Written in YAML

The hardest part of writing YAML is knowing when text needs quotes. A plain true, 123 or null would be read as a boolean, number or null, not as text. The tool adds quotes in these cases so the meaning of your data does not change.

JSON value YAML output Why
"hello" hello Safe as plain text.
"true", "123", "null" 'true', '123', 'null' Quotes keep them as text.
"yes", "on" 'yes', 'on' Older YAML parsers read these as booleans.
"2024-01-15" '2024-01-15' Some parsers read it as a date.
"a: b", "x #y" 'a: b', 'x #y' A colon with a space or a hash would change the meaning.
"" '' An empty value would become null.
"line1\nline2\n" | block with two lines Easier to read than \n.
[] and {} [] and {} Empty lists and objects stay on one line.

Your key order is kept exactly, even when a key looks like a number. Numbers are written with their original digits, so a large whole number does not lose precision. Numbers with an exponent, such as 1E5, are written as 1.0e+5, which every YAML version reads as a number.

Important! The quoting rules are deliberately careful, because they are meant to work with both older (1.1) and newer (1.2) YAML parsers. You may see a few extra quotes compared with hand-written YAML. That is safe and keeps the meaning of your data.

Common JSON Errors and How to Fix Them

Message Usual cause Fix
Trailing commas are not allowed in JSON A comma after the last item. Remove the last comma.
JSON strings must use double quotes Single quotes were used. Replace ' with ".
Text values and keys must be in double quotes An unquoted key or value, such as {name: "x"}. Quote the key: {"name": "x"}.
Comments are not allowed in JSON A // or /* */ comment. Remove the comment.
Unterminated string A closing quote is missing. Add the closing quote.
Expected "," or "}" A comma is missing between two items. Add the comma.

Limitations to Know

  • JSON has no comments. The YAML cannot include comments that were never in the JSON. Add them by hand afterwards.
  • No anchors or aliases. If your JSON repeats the same object, the YAML repeats it too. The tool does not detect repeats.
  • Long text is not folded. Lines stay as long as they are in the JSON.
  • Duplicate keys. JSON allows them, but most tools do not. The tool uses the last value and shows a note.
  • Strict JSON only. Files with comments, trailing commas or single quotes (sometimes called JSON5) must be fixed first.

Frequently Asked Questions

Is the JSON to YAML Converter free, and is my data uploaded?

It is free and needs no signup. The conversion runs in your browser, so your JSON stays on your device.

Why are some of my values in quotes in the YAML?

Quotes are added when plain text could be misread, for example as a number, boolean, null or date, or when it contains characters that have a special meaning in YAML. Without the quotes, the value could change type.

Will the YAML mean exactly the same as my JSON?

Yes. Text stays text, numbers stay numbers, and booleans, null, lists and objects keep their structure and order. Only the writing style changes.

How do I turn the YAML back into JSON?

Use a YAML to JSON converter. Keep in mind that YAML comments and anchors do not exist in JSON, so they are lost in that direction.

Which indentation should I use?

Use 2 spaces unless your project says otherwise. YAML only requires that you use spaces and stay consistent. Tabs are not allowed for indentation.

Why does my JSON show an error?

Most errors come from trailing commas, single quotes, comments or unquoted keys, which are not valid in JSON. The message shows the line and column and a pointer to the spot, so you can fix it quickly.

Final Thoughts

A good conversion keeps the meaning of your data and makes the result easy to read. Paste your JSON, fix any error the tool points out, keep the quoting on "Only when needed" for clean files, and check the YAML before you commit it to your project.

Post a Comment