JSON to YAML Converter
Paste JSON and convert it to clean, indented YAML — handy for Kubernetes manifests, Docker Compose files, GitHub Actions and other YAML-based configuration.
What this JSON to YAML converter does
The converter parses your input with the browser’s JSON.parse and writes it out as block-style YAML using the open-source js-yaml library (version 4). Objects become indented mappings, arrays become - list items, numbers, booleans and null keep their types, and any string that YAML could misread is quoted so that the YAML means exactly what the JSON meant.
Every JSON document is already valid YAML 1.2, so the point of converting is readability: the block style drops braces, brackets and most quotes, and once the data is in YAML you can add # comments, which JSON does not allow. That is why Kubernetes manifests, Docker Compose files, GitHub Actions workflows and OpenAPI documents are usually written in YAML even when tools generate or consume JSON.
How to use the converter
- Paste JSON into the JSON Input pane, or load it with File or URL (a URL must allow cross-origin requests).
- Choose an Indent of 2 spaces or 4 spaces.
- Click Convert. Invalid JSON produces an error starting with
Invalid JSON:, followed by your browser’s own message, which differs between browsers. - Copy the YAML, Download it as
converted.yaml, or Clear both panes.
The output pane opens on a tree of your JSON input, which is handy for checking structure before converting. Tree Viewer switches back to it after a conversion, and clicking a node copies its path.
Options explained
- 2 spaces — the most common style in YAML configuration files. List items are indented under their key (
ports:then- port: 80). - 4 spaces — wider indentation. With this setting js-yaml places the
-of a list item that holds an object or another list on its own line, with the content indented below it. That is valid YAML, but it looks different from hand-written files; choose 2 spaces if you want the familiar- name: Installlayout.
Long strings are never folded onto several lines, and the output does not start with a --- document marker.
What changes between JSON and YAML
| JSON | YAML output | Why |
|---|---|---|
"yes", "off", "NO" | 'yes', 'off', 'NO' | YAML 1.1 parsers would read these as booleans. |
"123", "3.10", "0x1F", "1e3" | Single-quoted | Unquoted, they would be numbers. |
"null", "~", "" | 'null', '~', '' | Unquoted, they would be null. |
"2024-01-15" | '2024-01-15' | js-yaml and many other parsers read unquoted dates as timestamps. |
"key: value", "#hash", "- dash" | Single-quoted | Colons, # and a leading - have syntax meaning. |
"line1\nline2\n" | Literal block | | Multi-line text stays readable; |- is used when there is no final newline. |
"tab\there" | "tab\there" | Control characters need double quotes and escapes. |
[], {} | [], {} | Empty collections are written in flow style. |
Keys are quoted by the same rules, so a key named n or "0" comes out as 'n' or '0'. Accented letters and emoji are written as they are. To see why these quoting rules matter, read YAML pitfalls.
Example: a Kubernetes Service
{"apiVersion": "v1", "kind": "Service",
"metadata": {"name": "web", "labels": {"app": "web"}},
"spec": {"ports": [{"port": 80, "targetPort": 8080}], "selector": {"app": "web"}}}
converts with 2-space indentation to:
apiVersion: v1
kind: Service
metadata:
name: web
labels:
app: web
spec:
ports:
- port: 80
targetPort: 8080
selector:
app: web
Common problems and fixes
| Problem | Cause | Fix |
|---|---|---|
Invalid JSON: error | Trailing commas, comments, single quotes or unquoted keys — often because the input is a JavaScript object, not JSON. | Fix the syntax; JSON syntax errors explained covers each case. |
| A duplicated key appears only once | JSON.parse keeps the last value for a repeated key, so {"a":1,"a":2} gives a: 2. | Remove the duplicate in the source. |
| A large number has changed | Integers above 253 lose precision when parsed. | Keep IDs and very large numbers as strings. |
| Key order looks different | Keys that look like whole numbers ("0", "1") are moved first, as in all JavaScript objects. | Use non-numeric keys if order matters. |
| The YAML library has not loaded | The js-yaml script from the jsDelivr CDN is blocked or still loading. | Wait a moment, or allow cdn.jsdelivr.net in your content blocker. |
Frequently asked questions
Why are some strings wrapped in single quotes?
Without quotes, YAML would read values such as yes, 3.10 or null as a boolean, a number or null. js-yaml quotes them so they stay strings when the file is read back, including by older YAML 1.1 parsers.
Can I paste a JavaScript object literal?
No. The input must be strict JSON: double-quoted keys and strings, no trailing commas and no comments. Clean it up in the JSON Formatter first.
Does the output use anchors and aliases?
No. Parsed JSON never contains shared references, so repeated sections are written out in full. You can introduce &anchor and *alias by hand afterwards if you want to deduplicate a configuration.
How are multi-line strings such as scripts converted?
They become literal block scalars: | followed by the lines, indented. This is the usual way to write shell commands in CI files, and the line breaks are kept exactly.
Is my JSON uploaded?
No. Parsing and conversion run in your browser, so secrets in a configuration file never leave your machine. The page loads the js-yaml library from the jsDelivr CDN, but your data is not sent with it.
Guides
How to Pretty-Print JSON in JavaScript, Python, jq and VS Code
Format JSON with indentation from the command line, in code and in your editor: JSON.stringify, python -m json.tool, jq and VS Code.
JSON vs YAML vs XML: Differences and When to Use Each
How JSON, YAML and XML differ in syntax, data types, comments, schemas and tooling, and which to choose for APIs, configuration and documents.