A JSON to YAML converter rewrites structured data from one format into the other without changing what it means. Paste your JSON and press Convert, and this JSON to YAML converter produces clean, indented YAML that's ready for a configuration file. Switch the direction to turn YAML into JSON for an API or a script. If something is wrong with your input, you'll see an error message that describes the problem. Everything runs in your browser, so configuration files and any secrets inside them stay on your device.
How to use the JSON to YAML converter
- Choose a direction.
- Paste your data into the box.
- Pick an indent of 2 or 4 spaces.
- Press Convert.
- Copy the result. Switching direction carries your last answer across, ready to convert back.
A worked example
Take this JSON: {"name":"Ada","skills":["math","code"],"active":true,"age":36}. The converter produces four top-level keys. The name becomes name: Ada on its own line. The skills list appears as skills: followed by two indented lines, - math and - code. The last two lines are active: true and age: 36. The braces, brackets and most of the quotation marks have gone, because YAML shows structure through indentation.
JSON and YAML compared
| JSON | YAML | |
|---|---|---|
| Structure | Braces and brackets | Indentation |
| Strings | Always in double quotes | Quotes are often optional |
| Comments | Not supported | Start with # |
| Common use | Data exchange and APIs | Configuration files |
What is JSON?
JSON is an open standard file format and data interchange format that uses human-readable text to store and transmit data objects. It has a small set of types: numbers, strings delimited with double quotation marks, the Boolean values true and false, ordered arrays, objects made up of name-value pairs, and null. Because it's so simple and strict, it's easy for programs to produce and to read.
What is YAML?
YAML is a human-readable data serialization language that's commonly used for configuration files. JSON syntax is a basis of YAML version 1.2, which was released with the express purpose of bringing YAML into compliance with JSON as an official subset. YAML also has additional features that JSON doesn't have, including comments.
YAML rules that catch people out
- Use spaces, not tabs. Tab characters aren't allowed in the indentation.
- Put a space after each colon. YAML requires it between a key and a value.
- Keep items aligned. Entries at the same level need the same indentation.
- Separate comments with a space. A comment begins with #, and it needs whitespace before it when it follows other text.
- Quote values that could be misread, such as those that look like numbers or dates.
What happens to comments?
JSON doesn't provide any syntax for comments. If you convert YAML to JSON, then any comments in your file will be dropped, because there's nowhere for them to go. If your comments matter, keep a copy of your original YAML. Going from JSON to YAML is a safe trip, since there's nothing to lose.
When to convert
- Configuration: many deployment and build tools read YAML.
- APIs: web services usually expect JSON.
- Readability: YAML can be easier to review by hand.
- Debugging: convert a confusing file to see how it's actually being read.
Reading error messages
Your data must be valid before it can be converted. Common causes of JSON errors are a trailing comma, a missing quotation mark or a single quote where a double one is needed. YAML errors usually come from inconsistent indentation or an unclosed bracket. The message tells you what the parser found and often where it stopped. Fix that spot, press Convert again, and repeat until the conversion succeeds.
Privacy
Configuration files often contain passwords, keys or internal addresses. This page converts everything in your browser, so none of your text is sent to our server. Close the page when you've finished, and take care where you paste the result.
Choosing an indent
Indentation carries meaning in YAML, so it needs to be consistent. Two spaces is the most compact choice and keeps deeply nested files from spreading across the screen, while four spaces make each level easier to see. Either one is valid, so follow whatever the rest of your project uses. The setting also applies when you convert YAML to JSON, where it controls how the result is laid out for reading. If you plan to send that JSON to a program, the layout makes no difference to its meaning, but a readable version is far easier to check by eye. A good habit after any conversion is to convert the result back again and compare it with your starting point. Press the switch to change direction, press Convert once more, and confirm that your keys and values have come through just as you expected.
Common mistakes
- Pasting tabs into YAML. Replace them with spaces.
- Expecting comments in JSON. They can't be kept.
- Assuming that the output is sorted. Keys stay in their original order.
Related developer tools
Validate your data with the JSON formatter, convert to another format with the JSON to XML converter, and tidy your code with the HTML formatter.
What next
Use this often? Add JSON to YAML to your Home screen.
Frequently asked questions
How does the JSON to YAML converter work?
It reads your JSON, checks that it's valid, and writes the same data as indented YAML.
Can it convert YAML to JSON?
Yes. Choose YAML to JSON, paste your YAML and press Convert.
Are YAML comments kept?
No. JSON has no comments, so they can't be carried across.
Why am I getting an error?
Your input isn't valid. Check for trailing commas in JSON, or tabs and uneven indentation in YAML.
Is my data uploaded?
No. The conversion happens in your browser.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.