JSON to YAML Converter
Convert JSON to YAML and YAML to JSON in one place. Swap directions with one click, pick the indentation and get errors with exact line and column numbers.
Convert JSON to YAML and YAML to JSON
YAML is the format of Kubernetes manifests, GitHub Actions, Docker Compose and OpenAPI files; JSON is what APIs, browsers and most programming languages produce. This JSON to YAML converter moves configuration between the two in either direction, so you can write YAML by hand and validate it as JSON, or turn an API response into a readable config file.
Strings that YAML could misread, such as no or 02134, are quoted automatically, anchors and merge keys are expanded when reading YAML, and syntax errors point to the exact line and column. The conversion uses the open-source js-yaml library and runs entirely in your browser.
How to convert JSON to YAML (or YAML to JSON)
- Pick a direction: JSON → YAML or YAML → JSON. The input box accepts pasted text or an opened file.
- Paste your data. The output updates as you type, and an invalid document shows the line, column and reason.
- Adjust the format: 2 or 4 space indentation, single or double quotes for YAML, minified JSON, or keys sorted alphabetically.
- Use Swap to send the output back as the new input, for example to round-trip a file and compare.
- Copy or download the result as
data.yamlordata.json.
How JSON maps to YAML
YAML 1.2 is a superset of JSON, so every JSON document has an exact YAML equivalent:
| JSON | YAML |
|---|---|
Object {"port": 8080} | Mapping port: 8080 |
Array ["web", "docs"] | Sequence, one - web item per line |
| Nested object | Indented block (2 or 4 spaces, never tabs) |
"text" | text (plain) or 'text' when quoting is needed |
"Line one\nLine two" | Literal block | with the lines below it |
true, false, null | true, false, null |
{}, [] | {}, [] (flow style) |
Edge cases the converter takes care of
- Strings that look like other types are quoted:
"no","on","yes"become'no','on','yes', and"02134"becomes'02134'. Older YAML 1.1 parsers would otherwise read them as booleans or numbers, the classic “Norway problem” where the country codeNOturns intofalse. - Special characters: values containing
:, a leading#,*or&are quoted so they are not read as keys, comments, aliases or anchors. - Long lines are not folded, so URLs and commands stay on one line.
- Anchors and merge keys such as
&defaults,*defaultsand<<: *defaultsare expanded into full copies in the JSON. - Several documents separated by
---become a JSON array with one item per document. - YAML 1.2 core schema:
yes,no,onandoffstay strings, and dates such as2024-01-15stay strings instead of turning into timestamps. - Comments (
# …) are dropped, because JSON has no comments.
Reading YAML error messages
YAML is sensitive to indentation, so most errors are about spaces. The message shows the position and a few lines around it, for example bad indentation of a mapping entry at line 2, column 3 when a key is indented by one space too many. Other common ones: end of the stream or a document separator is expected (a stray value after a mapping), duplicated mapping key (the same key twice) and unknown tag !<!Ref>, which appears for AWS CloudFormation short tags such as !Ref and !Sub; those are not part of standard YAML.
Tips
- Indent YAML with spaces only. A tab character in the indentation is a syntax error.
- Use the YAML → JSON direction as a quick validator: if JSON comes out, the YAML parses, and you can see exactly how each value was typed.
- Turn on “Sort keys A–Z” to compare two configs that list the same keys in a different order.
- JSON numbers are JavaScript numbers, so integers above 9,007,199,254,740,991 lose precision in both directions. Quote such IDs.
- Working with other formats too? Try TOML to JSON, JSON to CSV or XML to JSON.
Frequently Asked Questions
Common questions about converting between JSON and YAML.
Choose JSON → YAML, paste your JSON and copy the YAML from the output box. Objects become indented mappings and arrays become lists of - items.
Click YAML → JSON (or Swap) and paste the YAML. Comments are removed, anchors and merge keys are expanded, and you can pretty-print or minify the JSON.
YAML 1.2 is designed so that valid JSON is also valid YAML, with very rare exceptions. The reverse is not true: comments, anchors and multiple documents have no JSON equivalent.
Strings such as no, on, yes or 02134 are quoted so that YAML parsers keep them as text instead of reading them as booleans or numbers.
Most YAML errors come from indentation: mixing tabs and spaces, or nesting a key by the wrong number of spaces. The message shows the line and column where the parser stopped.
Yes. Documents separated by --- are converted into a JSON array, one element per document.
No. Dates such as 2024-01-15 stay as strings, which keeps them identical in the JSON output.
No. The js-yaml library is loaded from a CDN and then all parsing and conversion happens in your browser.