How to convert JSON to YAML, or YAML to JSON
- 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.
- 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.
- 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.
- 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.
- When you convert JSON to YAML, Safe for YAML 1.1 readers (on by default) puts quotes around every text that some reader could take for something else: yes and no, numbers with leading zeros such as
010(8 in YAML 1.1), times such as1:20(80 in YAML 1.1), dates such as2024-01-02and words such asnullor~. Numbers are written so both versions read the same number:1e5becomes1.0e+5, because PyYAML takes1e5for text. - When you convert YAML to JSON, choose the version your program uses under Read YAML as. The notes then list the values the other version reads differently, with their line numbers, so you can add quotes before they cause a bug.
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
- AWS CloudFormation templates in YAML use short forms such as
!Ref MyBucket,!Sub '${AWS::StackName}-data'and!GetAtt MyBucket.Arn. They become the full JSON form ({"Ref": "MyBucket"},Fn::Sub,{"Fn::GetAtt": ["MyBucket", "Arn"]}), exactly the way AWS cfn-flip converts them. - Kubernetes files often hold several objects split by
---. They become one JSON list, and a JSON list can be written back to separate YAML documents with Each list item in its own document. - Other tags, such as
!includeor!vault, have no JSON form. The value under the tag is kept and the notes name the tags that were dropped.
The most common YAML mistakes
- Tabs for indentation. YAML allows only spaces at the start of a line. A tab copied from an editor is the most common reason a file will not load.
- Indentation that does not line up. Items of one list or map must start in the same column, and a value that belongs to a key must be indented further than the key.
- No space after the colon.
name:Adais one piece of text; writename: Ada. - The same key twice in one map. Some readers keep the last one, others refuse the file; this tool shows you where the second one is.
- Values that start with special characters such as
@,`,%,*or&, or that contain:or#. Put them in quotes. - Unquoted values that are not text, such as yes, no, 010 or 3.10. They turn into true, false and numbers; quote them to keep them text.
Tips
- Check and tidy JSON before or after converting with the JSON formatter, which also repairs common mistakes and shows a tree.
- Working with XML or spreadsheets? The XML formatter converts XML to JSON, and the CSV to JSON converter turns a spreadsheet into JSON.
- Compare two configuration files by converting both with the same settings and pasting the results into the text compare tool, so only real changes show.
- Sort keys A to Z before comparing two versions of a file whose keys are in a different order.
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.