YAML vs JSON: what is the difference?

JSON and YAML describe the same kind of data: objects, lists, text, numbers, true, false and null. JSON is strict and made for programs, YAML is relaxed and made for people writing configuration by hand. This guide compares them side by side, shows the YAML rules that silently change values, and explains how to convert between the two without surprises. The converter below runs in your browser, so you can try every example as you read.

5 min read

The same data in both formats

Here is a small configuration in JSON: {"name": "shop", "port": 8080, "debug": false, "hosts": ["a.example.com", "b.example.com"]}. In YAML the same data is written with indentation instead of braces: name: shop on one line, port: 8080 on the next, debug: false, and hosts: followed by two indented lines that start with a hyphen.

Both load into exactly the same object in any programming language. The difference is in how they are written and in what else each format allows.

JSONYAML
StructureBraces and bracketsIndentation, or braces if you like
TextAlways in double quotesQuotes usually optional
CommentsNot allowedLines starting with #
Multi line textOnly with \n inside a stringBlocks with | or >
Reusing partsNot possibleAnchors (&name) and aliases (*name)
Several documents in one fileNoYes, separated by a line of three hyphens
Typical useAPIs, data exchange, browsersConfiguration: Docker Compose, Kubernetes, CI

Try it here: YAML to JSON

Open the full tool page

Why YAML is pleasant to write

YAML needs fewer characters. There are no closing braces to count, no commas to forget between items and no quotes around most text. Comments let you explain why a setting exists, which is why tools that people edit every day, such as Docker Compose, Kubernetes, GitHub Actions and Ansible, chose it.

Anchors avoid repetition: you define a block once with &defaults and reuse it with *defaults, or merge it into another block with <<: *defaults and override single keys. Block text keeps line breaks, which makes scripts and long messages readable inside the file.

YAML traps that change your data

The freedom to leave out quotes comes at a price: YAML guesses the type of every unquoted value, and the guess is not always what you meant. Most of these problems disappear when text is in quotes.

  • The Norway problem: in YAML 1.1, which many tools still use, NO, no, yes, on and off are booleans. A list of country codes with NO for Norway turns into false.
  • Version numbers: 1.10 is the number 1.1, and 3.0 may become 3. Write "1.10" to keep it as text.
  • Leading zeros: postal codes and product codes like 0123 can become numbers, and YAML 1.1 reads them as octal, so 0123 becomes 83.
  • Times: in YAML 1.1, 12:30 is a base 60 number, 750.
  • Colons and hashes: a value containing ": " or " #" ends the value early or starts a comment. Put such text in quotes.
  • Tabs: YAML does not allow tabs for indentation, and a key that is indented one space too far ends up in the wrong block without any error in some editors.

Why JSON is better for programs

JSON has one way to write each thing and no guessing: text is always quoted, so "NO" stays text and 1.10 is clearly a number. Parsers are small, fast and available in every language, and browsers read JSON natively. That makes JSON the safer choice whenever data is produced and read by software, such as API responses, logs, caches and data files.

The lack of comments is the most common complaint. Some tools accept JSON with comments (often called JSONC), but standard parsers reject it, so it is not a good format for files that other programs must read.

Converting between YAML and JSON safely

YAML 1.2 was designed as a superset of JSON, so almost any JSON document is also valid YAML. The other direction needs a real parser, because YAML features must be resolved: anchors and merge keys are expanded, block text becomes a string with \n, and several documents become a list. Comments cannot be carried over, since JSON has no place for them.

When you convert JSON to YAML, every value that a YAML reader could misread must be quoted. The converter on this page checks each text value against both YAML 1.1 and YAML 1.2 rules and quotes it only when needed, so yes, NO, 0123 and 1.10 come back unchanged. Converting the result back with Swap is a quick way to prove that nothing changed.

Which one should you use?

  • Use YAML for configuration that people write and review by hand, especially when comments help.
  • Use JSON for data that programs exchange, store or send over the network.
  • Use JSON when the file is generated by code, even if a person reads it later.
  • If a tool accepts both, as many do, keep the format your team already uses: consistency matters more than the small differences.
  • If you stay with YAML, quote text values that look like numbers, dates or yes/no, and check files with a parser before you deploy them.

Step by step

  1. Choose the directionSelect YAML > JSON or JSON > YAML at the top of the converter.
  2. Paste your filePaste the content or open the file. Sample shows a YAML file with an anchor and a merge key.
  3. Read the messagesIf the YAML has a mistake, the error shows the line and column. Notes list unknown tags and comments that were left out.
  4. Check the round tripPress Swap to convert the result back and compare it with your original.

Frequently asked questions

Is JSON valid YAML?

Almost always. YAML 1.2 is designed as a superset of JSON, so a YAML 1.2 parser reads JSON files. Older YAML 1.1 parsers have a few differences, for example with some escape sequences.

Is YAML slower than JSON?

Parsing YAML takes more work because of its many rules, but for configuration files the difference is not noticeable. For large data sets and APIs, JSON is faster and simpler.

Why does my YAML file say yes but the program sees true?

The program uses a YAML 1.1 parser, where yes, no, on and off are booleans. Put the value in quotes to keep it as text.

Can I keep comments when converting YAML to JSON?

No. JSON has no comments, so they are dropped. Keep the YAML file as the source if the comments matter.

Are my files uploaded when I convert them here?

No. The conversion runs entirely in your browser, which matters for configuration files with passwords or keys.