How to use the json to yaml converter
- Paste or type your JSON into the input area. Invalid JSON shows the line, column and position of the problem.
- Choose an indentation of 2 or 4 spaces, and optionally sort keys or use literal blocks for multi-line strings.
- The YAML output appears automatically as you type.
- Copy the result into your configuration files or pipelines.
How the conversion works
A JSON to YAML converter translates JSON syntax into YAML block style. Objects become indented key-value pairs, arrays become lines starting with a hyphen, and scalars are written directly. For example, the JSON {"a": 1, "b": [1, 2]} becomes:
a: 1
b:
- 1
- 2
Each nesting level adds the chosen indentation (2 or 4 spaces). In an array of objects, the first key sits right after the - and the remaining keys line up under it, so the result stays valid at either indentation. Key order is kept exactly as in your JSON, including keys that look like numbers, unless you tick the sort option.
Empty arrays are written as [] and empty objects as {}. Null is written as null, and booleans as true and false.
When strings need quotes
YAML lets many strings go unquoted, but a plain scalar is typed by its content. The text no is a boolean in many parsers and 12:30 can load as a number. This converter wraps a string in double quotes when it:
- Is empty (
"") or has leading or trailing whitespace - Contains
:or#, or ends with a colon - Starts with a special character such as
- ? : , [ ] { } # & * ! | > ' " % @ ` - Matches a boolean or null word in any case:
true,false,yes,no,on,off,y,n,null,~ - Looks like a number: integers, floats,
1e3, hex (0x1F), octal (0o17),.inf,.nan, underscored numbers such as1_000, and times such as12:30 - Starts like a date, for example
2024-01-15 - Contains a tab, a control character or another character YAML cannot hold raw
Object keys follow the same rules, so the key "true" or "1" stays a string key. Inside double quotes the converter escapes \", \\, \n, \r, \t and any control character as \uXXXX.
By default a multi-line string is a double-quoted string with \n escapes. If you tick the literal block option, text that can be represented faithfully is written as a | block, with - or + markers for its trailing newlines. Strings that a block cannot hold exactly, such as lines made only of spaces, fall back to double quotes.
Common use cases
Converting JSON to YAML is common in several development workflows:
- Kubernetes manifests: Kubernetes accepts both formats, but YAML is preferred for readability. Developers often generate JSON programmatically and then convert it before committing to version control.
- CI/CD pipelines: Tools like GitHub Actions, GitLab CI, and Ansible use YAML configuration. When exporting settings from an API that returns JSON, a quick conversion saves manual rewriting.
- Configuration files: Many applications support YAML config files. Converting from JSON lets you migrate without losing structure.
- Data inspection: YAML's lack of braces and commas makes deeply nested data easier to scan visually compared to raw JSON.
If you need to go the other direction, use the YAML to JSON converter to parse YAML back into structured JSON.
Edge cases and error handling
The converter first checks your input as strict JSON. If it is invalid, the message names the problem and gives the line, column and character position, which makes missing commas, trailing commas and unmatched brackets easy to find.
Numbers are copied from your text digit for digit. 1234567890123 stays 1234567890123, and 12345678901234567890 keeps all twenty digits, because the converter does not turn them into JavaScript numbers. A float with an exponent is rewritten in a form that both YAML 1.1 and 1.2 parsers read as a number: 1E5 becomes 1.0e+5. Be aware that a program that later reads the YAML into double-precision floats, such as JavaScript, will round integers beyond 253, so keep very large IDs as strings if they must survive that step.
If a key appears twice in the same object, the last value wins and the key keeps its first position, matching how JSON.parse behaves. The output was checked by loading it back with PyYAML for 500 generated documents full of awkward strings, at both indentations, and every one produced the original data.
For related format conversions, you can also convert JSON to TypeScript interfaces or transform XML to JSON before converting to YAML.
JSON and YAML comparison
| Feature | JSON | YAML |
|---|---|---|
| Syntax | Braces, brackets, commas | Indentation, hyphens |
| Comments | Not supported | Supported with # |
| Key quotes | Always required | Optional when the key cannot be mistaken for another type |
| String quotes | Always required | Optional when unambiguous |
| Trailing commas | Not allowed | Not applicable |
| Multi-line strings | Escaped \n | Literal blocks or escaped |
| Anchors and aliases | Not supported | Supported with & and * |
Both formats represent the same basic data model of maps, sequences, scalars and nulls. Valid JSON is also valid YAML 1.2 in nearly every case, though the reverse is not true. YAML 1.1 parsers, which many tools still use, read a few plain words differently, which is why this converter quotes them.
Worked examples
| Example | Input | Result |
|---|---|---|
| Simple object | JSON input: {"a":1,"b":[1,2],"c":{"d":"x"}}; Indentation spaces: 2; Sort keys alphabetically: no; Use literal blocks (|) for multi-line strings: no | a: 1 / b: / - 1 / - 2 / c: / d: x / |
| Strings that look like other types | JSON input: {"s":"true","n":"null","t":"12:30","d":"2024-01-15"}; Indentation spaces: 2; Sort keys alphabetically: no; Use literal blocks (|) for multi-line strings: no | s: "true" / "n": "null" / t: "12:30" / d: "2024-01-15" / |
| Empty collections | JSON input: {"e":[],"o":{}}; Indentation spaces: 2; Sort keys alphabetically: no; Use literal blocks (|) for multi-line strings: no | e: [] / o: {} / |
| Array of objects, 4 spaces | JSON input: [{"id":1,"n":"a","tags":["x","y"]},{"id":2,"n":"b"}]; Indentation spaces: 4; Sort keys alphabetically: no; Use literal blocks (|) for multi-line strings: no | - id: 1 / "n": a / tags: / - x / - "y" / - id: 2 / "n": b / |
| Multi-line text as literal block | JSON input: {"note":"line one\nline two\n"}; Indentation spaces: 2; Sort keys alphabetically: no; Use literal blocks (|) for multi-line strings: yes | note: | / line one / line two / |
FAQ
Is this JSON to YAML converter free?
Yes, it is completely free with no usage limits. All processing happens locally in your browser.
Does my data get uploaded anywhere?
No. The conversion runs entirely in your browser using JavaScript. Your JSON input never leaves your device.
Can I convert YAML back to JSON?
Yes. Use the companion YAML to JSON tool to reverse the process.
Why are some strings wrapped in double quotes?
Strings that a YAML parser would read as booleans, numbers, dates, times or null, or that start with special characters, are quoted so they stay strings. Keys such as "true" or "1" are quoted for the same reason.
Are large numbers kept exactly?
Yes. The digits are copied from your JSON text, so 12345678901234567890 is written as is. Note that a program that later loads the YAML into floating-point numbers, such as JavaScript, may round integers above 2^53.
What indentation sizes are supported?
You can choose 2 or 4 spaces. Arrays of objects stay valid at both sizes: the first key follows the hyphen and the other keys line up under it.
Can I get multi-line strings as literal blocks?
Yes. Tick the literal block option and multi-line strings that a block can hold exactly are written with the | style. Otherwise they are double-quoted with \n escapes.
Does it handle large JSON files?
It works well for typical configuration files and API responses. Extremely large files may slow the browser tab because processing happens client-side.
Are comments preserved during conversion?
JSON does not support comments, so there are none to preserve. If you need to add comments, edit the YAML output after conversion.