Skip to content
DeviceCheckHub

JSON to YAML Converter

Paste JSON to get YAML, or paste YAML to get JSON: the YAML to JSON converter works the other way on the same page. Mistakes are shown with the exact line and column, and the notes warn you about values that different YAML readers understand differently.

Paste or open JSON or YAML and it is converted here. Nothing is uploaded.

  • Notes about the conversion appear here, such as values that YAML 1.1 and 1.2 readers see differently.

How to convert JSON to YAML, or YAML to JSON

  1. Paste your text into Your JSON or YAML, or press Open a file to load a .json, .yaml, .yml or CloudFormation template. You can also drag a file onto the box. The two example buttons fill it for you.
  2. The tool works out which one you pasted and converts it while you type: JSON becomes YAML, and YAML becomes JSON. To choose the direction yourself, use Convert.
  3. If something is wrong, the box on the right shows the lines around the mistake with a marker under the exact spot, and the message says what is wrong in plain words. Go to the mistake puts your cursor there.
  4. Read the notes under the result, then press Copy result or Download. Use result for my text moves the result into the left box, so you can convert it back or keep editing.

JSON and YAML: the same data, two ways to write it

JSON and YAML both describe maps of keys and values, lists, text, numbers, true and false, and null, so any JSON can be written in YAML. JSON uses braces, brackets, quotes and commas, which makes it strict and easy for programs to send to each other. YAML uses indentation and dashes instead, which makes it easier to read and edit by hand; that is why Kubernetes, Docker Compose, GitHub Actions, Ansible and CloudFormation use it for configuration. In fact, YAML 1.2 is a superset of JSON: a valid JSON file is also a valid YAML file.

YAML can hold a few things JSON cannot: comments, anchors and aliases that reuse a value, merge keys, tags such as !Ref, and several documents in one file. When YAML is converted to JSON, comments are left out, references are copied out in full, and the notes tell you about each change.

Yes, no, on and off: the Norway problem

In YAML 1.1, a bare yes, no, on or off means true or false. So a list of country codes with country: NO in it gives Norway the value false in PyYAML, and a GitHub Actions file read by PyYAML has true where it says on:. YAML 1.2 fixed this: only true and false are true and false. But YAML 1.1 readers are still everywhere, so the same file can mean two things.

Numbers stay exact

Many converters read JSON with JavaScript's own number type, which holds only about 16 digits. An ID or amount such as 12345678901234567890 then quietly becomes 12345678901234567000. This converter copies every number exactly the way it is written, in both directions, and keeps decimals decimal: 1.0 stays 1.0 instead of turning into the whole number 1.

The other way round there is a classic trap: in YAML, python: 3.10 without quotes is the number 3.1, so a version number loses its last digit. The tool warns about every value like that. Write "3.10" to keep it text.

Anchors, aliases and merge keys

YAML can name a value with an anchor (&defaults) and reuse it with an alias (*defaults). The merge key <<: *defaults copies all keys of the named map into another map, where keys written in that map win. JSON has no references, so each alias becomes a full copy and each merge becomes the combined map. The YAML example on this page shows a typical database settings file built this way.

CloudFormation, Kubernetes and other files

The most common YAML mistakes

Tips

Your files stay on your device

Configuration files often hold passwords, tokens and internal addresses, so everything happens in your browser: the reading, checking and converting all run on your own computer or phone, and nothing is sent to this website or anyone else. The page remembers your latest text and settings in your browser on this device so they survive a reload. Clear removes the text, and clearing the site’s data in your browser removes everything.

Frequently asked questions

Is my JSON or YAML uploaded to a server?

No. Reading, checking and converting all run in your browser, so nothing you paste or open is sent anywhere. That makes it safe for configuration files with passwords, keys or customer data in them. The page keeps your last text on this device so it is still there after a reload; press Clear to remove it.

Why does the YAML put quotes around yes, no, on and off?

Because YAML 1.1 readers, such as PyYAML (used by Ansible and many Python programs), turn a bare yes, no, on or off into true or false. A country code NO would turn into false, and the text off into false too. With quotes, every YAML reader keeps them text. The same goes for values that look like numbers or dates, such as 010, 1:20 or 2024-01-02. If your YAML is only read by YAML 1.2 tools, turn off Safe for YAML 1.1 readers and yes, no, on and off are written without quotes.

Should I read my YAML in version 1.2 or 1.1?

Choose the version of the program that reads your file. Most JavaScript tools (the yaml and js-yaml libraries) follow YAML 1.2, where only true and false are true and false. PyYAML, and so Ansible and many Python scripts, follow YAML 1.1, where yes, no, on and off are true and false and 010 is the number 8. Whichever you choose, the tool lists every value the other version would read differently.

Are YAML comments kept?

Not in JSON, because JSON has no comments; the notes say when comments were left out. In the other direction, JSON with comments or trailing commas, such as a tsconfig.json or a VS Code settings file, is still read: the comments are skipped and the notes list what was repaired.

Are big numbers and decimals kept exactly?

Yes. A whole number such as 12345678901234567890 is copied digit for digit, where many JavaScript converters round it to 12345678901234567000. A decimal keeps its decimal point, so 1.0 stays 1.0. One thing to know: a YAML value such as 3.10 written without quotes is a number, and a number has no trailing zeros, so it becomes 3.1; the tool warns you when that happens.

Can it convert Kubernetes files with several documents?

Yes. YAML with several documents split by --- becomes one JSON list with an item for each document. For the other way, turn on Each list item in its own document and a JSON list becomes YAML documents split by ---, the layout kubectl apply expects.

Does it understand CloudFormation tags such as !Ref and !Sub?

Yes. The short forms !Ref, !Sub, !GetAtt, !Join, !If and the other intrinsic functions become the full JSON form, such as {"Ref": "MyBucket"} and {"Fn::Sub": "…"}, the same way AWS cfn-flip converts them. Anchors (&name), aliases (*name) and merge keys (<<) are expanded too, because JSON has no references.

How big a file can it handle?

A file you open can be up to 5 MB, and pasting works for similar sizes. Everyday configuration files convert while you type; a file of a few megabytes can take a few seconds, and the page says when it is working. To protect your browser, YAML whose aliases would stand for more than 2,000,000 values (an alias bomb) is stopped with a message instead of freezing the page.

Last updated · About DeviceCheckHub