Conversion tool

JSON to YAML Converter (and YAML to JSON)

Convert JSON to YAML and YAML to JSON online. Strings like "yes" and "0123" stay strings, errors show the line and column, and nothing is uploaded.

Last updated

Paste JSON and get YAML back, or paste YAML and get JSON. It converts as you type, runs in your browser, and uploads nothing.

Convert
272 bytes

Valid JSON, converted to YAML. Nothing here leaves your browser.

Type or paste in the first box and the second updates as you go. Pick JSON → YAML or YAML → JSON for what you are pasting, or press Swap to flip the direction and move the output into the input, so you can check that it converts back to what you started with. Press Copy to take the result. Everything runs in your browser and nothing is uploaded.

What stays the same

A converter should change the format and nothing else. Here is what that means in practice.

In the JSONIn the YAMLWhy
"name": "Miso"name: MisoA plain word needs no quotes
"answer": "yes"answer: "yes"Unquoted, yes is a boolean in YAML 1.1
"zip": "0123"zip: "0123"Unquoted, 0123 is a number (octal in YAML 1.1)
"version": "1.5"version: "1.5"Unquoted, 1.5 is a float
"id": 9007199254740993id: 9007199254740993Every digit kept, even past what a JavaScript number can hold
"price": 1.0price: 1.0The decimal point stays
"note": "line one\nline two"note: |- then the linesMulti-line strings become a readable block
"tags": []tags: []Empty lists and objects stay inline

Keys come out in the order they went in. A converter that goes through a JavaScript object moves keys that look like numbers, such as "2" and "10", to the front. This one does not.

The "yes" problem

YAML 1.1, the version many parsers still speak (PyYAML, older Ruby and Go libraries), reads a lot of bare words as something other than text:

  • yes, no, on, off, y and n are booleans. The famous case is a list of country codes where Norway, NO, turns into false.
  • 0123 is octal, so it becomes 83. Phone numbers, ZIP codes and IDs with a leading zero lose it.
  • 12:30 is a base-60 number, 750.
  • 2001-12-14 is a date.

YAML 1.2 fixed most of this, but a file written for one parser is often read by another. So when converting JSON to YAML, every string that either version would misread is quoted. When converting YAML to JSON, the input is read as YAML 1.2, so a bare yes becomes the string "yes". If your YAML means a boolean, write true or false.

Several documents in one file

A YAML file can hold several documents separated by lines of ---, which is how Kubernetes manifests and many CI files put more than one object in a file:

kind: Service
---
kind: Deployment

Converting that to JSON gives an array with one item per document, and a note under the output says how many there were:

[
  { "kind": "Service" },
  { "kind": "Deployment" }
]

A single document that starts with --- is still a single value, and an empty document, such as a --- at the very end, is skipped.

Anchors, aliases and merge keys

YAML can name a value with an anchor (&name) and reuse it with an alias (*name). A << merge key copies one mapping's keys into another, which is how docker-compose files share settings between services. JSON has none of these, so they are expanded: the JSON holds a full copy of the value everywhere an alias pointed at it.

defaults: &defaults
  restart: always
  image: nginx
web:
  <<: *defaults
  restart: never

becomes "web": { "restart": "never", "image": "nginx" }: a key written on web itself wins over the merged one. A document whose aliases expand to more than a thousand copies is refused rather than allowed to freeze the page, since that is the shape of the "billion laughs" attack.

When it will not convert

The error says which line and column, with a caret under the spot. JSON errors use the same checks and wording as the JSON Formatter, so a trailing comma, a single quote or a missing bracket is named as exactly that. The common YAML ones:

  • A tab used for indentation. YAML only allows spaces. Most editors can convert tabs to spaces for you.
  • Items that do not line up. Every key in a mapping, and every - in a list, has to start in the same column.
  • A repeated key. YAML does not allow the same key twice in one mapping. Repeated keys in JSON are allowed, so going the other way the last value is kept, as JSON.parse would, and a note says so.
  • A colon followed by a space inside a plain value, such as title: Cats: a history. Put the value in quotes.
  • An unclosed [ or { in a flow list or mapping.

JSON or YAML?

JSONYAML
CommentsNoYes, with #
StructureBrackets and bracesIndentation
Quotes around stringsAlwaysOnly when needed
Reuse a valueNoAnchors and aliases
Multi-line strings\n escapesBlock scalars, | and >
Common inAPIs, package.json, browser storageKubernetes, docker-compose, GitHub Actions, Ansible

YAML is easier for people to write and review by hand, which is why config files use it. JSON is stricter and quicker to parse, which is why programs exchange it.

Common questions

How do I convert JSON to YAML online?

Paste the JSON into the box at the top of this page and the YAML appears next to it as you type. Press Copy YAML to take it. The conversion runs in your browser, so the JSON is never uploaded. The site records that the tool was used and how long the input was, never the text itself.

How do I convert YAML to JSON?

Press YAML to JSON above the boxes, or press Swap to flip the direction and carry the current output across as the new input. Paste your YAML and the JSON appears as you type, indented with two spaces. Anchors, aliases and merge keys are expanded, so the JSON has every value written out in full.

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

Because without quotes a YAML parser would read them as something other than a string. yes, no, on and off are booleans to YAML 1.1 parsers such as PyYAML, 0123 is an octal number, 1.5 is a float, null and ~ are null, and 2001-12-14 is a date. This converter quotes every string like that, so it comes back as the same string in any parser. Plain words and sentences stay unquoted.

What happens to a YAML file with several documents?

A YAML stream can hold several documents separated by --- lines, as a Kubernetes manifest often does. This converter turns them into one JSON array with one item per document, in order, and says so under the output. Nothing is dropped. An empty document, such as a trailing ---, is skipped.

Is this a YAML validator too?

Yes. If the YAML cannot be parsed, the tool shows the line and column of the problem, a caret under the spot, and a sentence saying what is wrong, such as a tab used for indentation, a key repeated in the same mapping, or items that do not line up. The same goes for JSON, with the same messages as the JSON Formatter.

Is YAML a superset of JSON?

Almost. Since YAML 1.2, any valid JSON document is also a valid YAML document, so a YAML parser can read JSON as it is. The reverse is not true: YAML adds comments, anchors, multi-line strings and indentation-based structure, none of which JSON has. Converting to JSON keeps the data and loses the comments.

Does converting keep comments?

No. JSON has no comments, so YAML comments have nowhere to go when converting to JSON, and there are none to carry over the other way. Everything else is kept: keys in their original order, integers exactly as written, even ones too large for JavaScript, and every string as the same string.

See all tools

Want this explained by a cat?

The videos cover the same ground in sixty seconds. If there is a tool you want built next, ask.