Skip to main content

JSON to YAML

Config-friendly output from any JSON document.

YAML is the format of choice for configuration: Kubernetes manifests, CI pipelines, Docker Compose, Ansible. Paste JSON here and get equivalent YAML you can drop straight into a config file.

YAML forbids tab indentation, so the output always uses spaces. Ambiguous scalars are quoted so they cannot be re-read as booleans or numbers.

Input JSON

Size: 0 BLines: 0

YAML output

Paste valid JSON to see the output.
Size: 0 BLines: 0

Same data, a surface built for editing

JSON and YAML describe the same three things: scalars, ordered sequences and key-value mappings. Converting between them is a change of notation, not of meaning — which is why this direction is the easy one. Every JSON document has a YAML equivalent, with no exceptions and nothing lost.

The reason to do it is that YAML is what configuration tooling expects. Kubernetes manifests, GitHub Actions and GitLab CI pipelines, Docker Compose, Ansible playbooks and OpenAPI specifications are all YAML by convention, and a pasted block of JSON in the middle of one is technically valid and socially wrong.

A real conversion

JSON
{
  "name": "checkout-service",
  "replicas": 3,
  "enabled": true,
  "note": null,
  "version": "1.0",
  "country": "no",
  "description": "line one\nline two\n",
  "tags": ["web", "payments"],
  "resources": { "limits": { "cpu": "500m", "memory": "512Mi" } },
  "empty": {},
  "none": [],
  "colon": "key: value",
  "hash": "#1 priority"
}
YAML
name: checkout-service
replicas: 3
enabled: true
note: null
version: '1.0'
country: 'no'
description: |
  line one
  line two
tags:
  - web
  - payments
resources:
  limits:
    cpu: 500m
    memory: 512Mi
empty: {}
none: []
colon: 'key: value'
hash: '#1 priority'

Key order is preserved exactly. Braces and brackets disappear in favour of indentation, except for empty collections, which keep the flow form because {} and [] have no block equivalent.

Why some strings get quotes and others do not

This is the only genuinely interesting decision in the conversion, and getting it wrong is how YAML files break. A string is quoted whenever leaving it bare would make a YAML parser read it as something other than a string.

ValueEmitted asBecause bare it would be
"1.0"'1.0'a number — and would come back as 1.
"no"'no'a boolean, under YAML 1.1 parsers.
"key: value"'key: value'a nested mapping — the colon-space is a separator.
"#1 priority"'#1 priority'an empty value followed by a comment.
"500m"500munambiguously a string already — no quotes needed.
"checkout-service"checkout-servicelikewise. Hyphens mid-word are fine.

The conversion is conservative in the right direction: it adds quotes when they are needed and leaves them off when they are not, so the output stays readable without being fragile. This is the same set of traps described from the other side on the YAML to JSON page — worth reading if you edit YAML by hand.

Multi-line strings become block scalars

A JSON string containing newlines is written with \n escapes, which is unreadable for anything longer than a sentence. YAML has a better answer, and the converter uses it automatically.

"description": "line one\nline two\n"

description: |
  line one
  line two

The | marker means "everything indented below this is a literal string, newlines included". It is the single biggest readability win of the format, and the reason embedded scripts in CI pipelines are bearable at all.

Indentation and key order

Two spaces is the default and is what essentially every YAML tool and linter expects. Four is available and legal; it makes deeply nested manifests wider without making them clearer. Sequences are indented under their key rather than hung at the parent level — both forms are valid YAML, and the indented one is what kubectl and the major linters emit.

Key order comes straight from the JSON and is never rearranged, which is the right default for configuration — order there is usually deliberate. apiVersion, kind, metadata, spec is the conventional opening of a Kubernetes manifest, and a converter that alphabetised it would be actively unhelpful. If you do want a canonical order for machine comparison, sort the JSON first with the beautifier and convert the result.

What the converter cannot invent

YAML has features JSON has no equivalent for, and nothing in your JSON can tell the converter where to use them.

  • Comments. JSON has none to carry over. If you are regenerating a config file that had comments, you will be adding them back by hand — which is a good argument for keeping the YAML as the source of truth and the JSON as a derived artifact.
  • Anchors and aliases. Repeated blocks are written out in full rather than collapsed into &defaults and *defaults. The output is correct, just more verbose than something hand-written.
  • Multiple documents. One JSON document produces one YAML document. Concatenate with --- separators yourself if you need several.
  • Explicit tags. Types are inferred from the values, which is what you want for configuration.

A round trip worth testing

JSON → YAML → JSON returns the same data, so long as the quoting is right — which is exactly what the converter handles for you. It is a genuinely useful sanity check: convert to YAML, paste the result into the YAML to JSON converter, and diff it against the original. Zero differences means the YAML you are about to commit says precisely what you think it says.

That check catches the one class of bug that hand-written YAML produces constantly: a version number, a postal code or a country code that quietly stopped being a string.

Frequently asked questions

Is every JSON document convertible to YAML?
Yes, without exception — YAML is a superset of JSON, so the data always has a YAML representation and nothing is lost in this direction.
Why are some of my strings wrapped in quotes?
Because without them a YAML parser would read the value as something else. "1.0" would become the number 1, "no" could become false, and "key: value" would be parsed as a nested mapping. The quotes are what keeps the round trip honest.
Which indentation does the output use?
Two spaces by default, which is what YAML linters and Kubernetes tooling expect. Four is available. Sequence items are indented under their key.
Are comments preserved?
There are none to preserve — JSON has no comment syntax. If your workflow needs commented YAML, keep the YAML as the source and treat generated JSON as an output.
What happens to multi-line strings?
They are written as block scalars using |, so the text appears as real lines rather than one string full of \n escapes.
Can I get anchors and aliases in the output?
No. Repeated structures are written out in full, because nothing in the JSON indicates which repetitions were meant to be shared. Add anchors by hand if the file is one people will maintain.
Is the conversion done on a server?
No. It runs in your browser, so configuration containing internal hostnames, service names or secrets never leaves your machine.