My Tool Studio
Developer

JSON to YAML Converter

This JSON to YAML converter rewrites JSON as block-style YAML, the layout that Kubernetes manifests, Docker Compose files and most CI configs use. It converts as you type: paste JSON on the left and the YAML appears on the right, or the bad line is highlighted if the JSON is not valid yet. Objects become indented keys, arrays become dash lists, and numbers, booleans and null keep their types. Choose 2 or 4 spaces, whether list items are indented under their key, the quote style, inline or block style and key sorting, or use the Kubernetes, Docker Compose and GitHub Actions presets. A top-level array can become separate --- documents. Paste, drop, upload or load JSON from a URL, then copy or download .yaml or .yml.

Always freeNo sign upRuns in your browser
Swap: YAML to JSON
Indent
Presets:
YAML appears here.

How to use

01

Add your JSON

Paste JSON into the left pane, drop or upload a .json file, use Load URL, or press Try sample to load a Kubernetes Deployment written as JSON. Conversion starts right away.

02

Pick a style

Press a preset, or set Indent, list indentation, Quotes, Style, key sorting and line wrapping yourself. Tick Top-level array as separate documents to split a list of objects with ---.

03

Copy or download

Press Copy above the YAML pane, or pick .yaml or .yml and press Download. If the JSON has an error, press Go to line to jump to it.

Why JSON to YAML Converter

JSON vs YAML syntax

JSON and YAML can describe the same data, but they look very different. YAML relies on indentation and dashes where JSON uses braces, brackets and commas, which makes config files shorter and easier to diff.

The table compares the main pieces. The YAML column shows what this converter writes.

Indentation carries meaning in YAML. This converter writes two spaces per level by default, or four if you choose, and mixing indent widths or using tabs in a YAML file causes parse errors.

ConceptJSONYAML
Key and value{"name": "web"}name: web
Nested object{"metadata": {"name": "web"}}metadata: on one line, then name: web indented 2 spaces below
List["a", "b"]- a and - b on separate lines
String that looks like a boolean"false"'false'
Number and boolean2 and true2 and true
Nullnullnull
CommentNot allowed# comment

Presets for common config files

The presets set the options that differ between popular tools. The YAML stays valid either way; the presets only match the style people expect to see in each kind of file.

PresetIndentList itemsQuotes
Kubernetes (kubectl style)2 spacesSame indent as the key (- name: web)Single, only when needed
Docker Compose2 spacesIndented under the keyDouble, only when needed
GitHub Actions2 spacesIndented under the keySingle, only when needed

Common questions

Is YAML a superset of JSON?
Almost. YAML 1.2 was designed so that valid JSON is also valid YAML, apart from rare edge cases. You could paste JSON into a .yaml file, but block-style YAML like this tool writes is easier to read and review.
Should I name the file .yaml or .yml?
Either works. The YAML project recommends .yaml, but .yml is common, and tools such as Docker Compose and kubectl accept both.
Why are some strings quoted in the YAML output?
A string that YAML would read as a number, boolean or null, like "false", "10" or "null", is quoted so it stays a string, and so are strings that start with characters such as * or &. Quotes decides whether those use single or double quotes, and Quote every string wraps all string values.
Does JSON to YAML keep the key order?
Yes, keys are written in the order they appear in the JSON unless you tick Sort keys A to Z. The exception comes from JavaScript: keys that look like whole numbers, such as "2" and "10", move to the front in ascending order.
Can I convert a Kubernetes manifest from JSON to YAML?
Yes. Press the Kubernetes preset for the kubectl layout, where list items sit at the same indent as their key. If your JSON is an array of several objects, tick Top-level array as separate documents to get one --- document per object, ready for kubectl apply -f.
Can the JSON to YAML converter add comments?
No. JSON has no comments, so there is nothing to carry over. Add # comments to the YAML by hand after you copy it.
How do I convert YAML back to JSON?
Use the YAML to JSON Converter. It also handles files with several documents separated by --- and expands anchors and aliases.
Is my JSON sent anywhere when converting to YAML?
No. The conversion runs in your browser with the js-yaml library, and nothing is uploaded.
What does the Style option in the JSON to YAML converter do?
Block writes one key per line, which is the usual config layout. Inline below depth 1 or 2 keeps the top levels in block style and writes deeper objects and lists in compact {key: value} and [a, b] form. All inline writes the whole document that way, which looks close to JSON.

More Developer tools

View all