JSON to YAML Converter — config a human can read
Paste JSON and get YAML that reads like somebody wrote it — 2 or 4 space indent, optional key sorting, and quoting handled for you. Good for Kubernetes, Compose, and CI configs.
What is a JSON to YAML converter?
A JSON to YAML converter takes a JSON document and produces an equivalent YAML file. JSON and YAML are designed to be interchangeable — they represent the same data structures (objects, arrays, strings, numbers, booleans, null) with different syntax. YAML is preferred for configuration files because it's more human-readable, supports comments, and avoids the visual noise of curly braces and quotation marks.
For example, this JSON:
{
"name": "web-server",
"image": "nginx:1.25",
"ports": [80, 443],
"environment": {
"DOMAIN": "example.com",
"DEBUG": false
}
}
becomes this YAML:
name: web-server
image: nginx:1.25
ports:
- 80
- 443
environment:
DOMAIN: example.com
DEBUG: false
The data is identical; only the syntax changes. YAML's indentation-based structure is easier to scan and edit by hand, which is why it's become the standard for configuration files in Kubernetes, Docker, Ansible, GitHub Actions, and dozens of other modern tools.
How to convert JSON to YAML in 3 steps
Most conversions take less than a minute. No login, no upload to a server, no installation.
-
Paste or upload
Drop a
.jsonfile into the upload zone, or paste JSON text. The converter parses it instantly and shows the YAML preview. -
Configure
Open the settings cog to choose the indent size (2 spaces for Kubernetes convention, 4 for readability), and whether to sort keys alphabetically.
-
Copy or download
Click Copy YAML to put the result on your clipboard, or Download YAML to save a
.yamlfile. Drop it straight into your project.
Built for the YAML you actually need
YAML has subtle rules around quoting, indentation, and key order. HopConvert handles them by default.
YAML 1.2 compliant
Output is valid YAML 1.2, the current standard. Works with every parser: Python, Ruby, Go, Node, Java, Kubernetes, Ansible.
2 or 4-space indent
2-space is the Kubernetes and Docker Compose convention. 4-space is more readable for deeply nested configs.
Smart key sorting
Optional alphabetical sort produces diff-friendly output that doesn't churn in version control when only values change.
Browser-only privacy
Every byte is processed in your browser. Nothing is uploaded, logged, or stored on our servers.
Multi-line strings
Strings with embedded newlines are emitted as YAML block scalars (|). Single-line strings stay on one line.
Live preview
The result panel updates as you type. See exactly what your YAML will look like before downloading.
JSON vs YAML: what's the difference?
Both formats store structured data, but they're designed for different jobs.
| Aspect | JSON | YAML |
|---|---|---|
| Syntax | Braces, brackets, commas, quotes | Indentation, colons, dashes |
| Best for | APIs, data interchange, machine-to-machine | Configuration files, human editing |
| File size | Smaller (less whitespace) | Larger (indentation is significant) |
| Human readability | Moderate (visual noise) | High (clean, scannable) |
| Comments | Not supported | # comments |
| References | JSON Pointer (complex) | Anchors (&) and aliases (*) — simple |
| Multi-line strings | Requires \n escapes | Literal block (|) or folded (>) |
| Standard | RFC 8259 | YAML 1.2 (no RFC) |
When teams reach for JSON to YAML
YAML is the lingua franca of modern infrastructure. The JSON→YAML conversion unlocks all of it.
Kubernetes manifests
Use kubectl get -o json to dump a resource, then convert it to YAML for editing and committing to a Git repo.
Docker Compose
Compose files are YAML. Generate a base config from a JSON spec, then customise per environment.
GitHub Actions
Convert a CI pipeline from a templating system to YAML, ready to drop into .github/workflows/.
Ansible playbooks
Generate Ansible tasks from an inventory JSON file. Hand-editing YAML is faster than the equivalent JSON.
Helm values
Helm chart values.yaml files are easier to maintain than their JSON equivalents. Convert a config once.
API documentation
Convert an OpenAPI spec from JSON to YAML for human review. Most OpenAPI tooling accepts both.
JSON to YAML: the complete guide
Everything you need to know about the YAML format, the conversion rules, and how to use YAML in real infrastructure.
YAML syntax basics
YAML uses three structural markers: indentation for hierarchy, colons for key-value pairs, and dashes for list items. Whitespace is significant — YAML does not use braces or brackets. A simple document:
name: web-server
replicas: 3
image: nginx:1.25
ports:
- 80
- 443
labels:
app: web
tier: frontend
The indentation (2 spaces per level) creates the hierarchy. A dash followed by a space introduces a list item. A colon followed by a space separates a key from its value. That's the whole syntax — YAML 1.2 is designed to be the most readable structured data format ever standardised.
YAML is also a strict superset of JSON: any valid JSON document is also a valid YAML document. That's what makes the conversion lossless.
How does the conversion work?
JSON has six value types: object, array, string, number, boolean, null. YAML has the same six types, plus extras like timestamps and binary data. The conversion is one-to-one for the shared types, with these rules:
- Objects become block-style mappings with each key on its own line, indented under the parent.
- Arrays become block-style sequences with each item prefixed by a dash.
- Strings stay unquoted unless they contain special characters or look like other types (numbers, booleans, null).
- Numbers stay as plain digits (no quotes), matching YAML's native number type.
- Booleans are emitted as
trueorfalse(lowercase, the YAML 1.2 canonical form). - Null is emitted as
nullor~(both are valid YAML).
JSON keys are always strings, so they become unquoted YAML keys (the standard practice). If a key would be ambiguous (e.g., contains a colon or starts with a number), the converter adds quotes automatically.
When does YAML need quotes?
YAML is permissive about quoting but strict about ambiguity. A string that could be parsed as a number, boolean, or null must be quoted to be treated as a string. Examples:
version: 1.0— parsed as a number unless quoted ("1.0")active: true— parsed as a boolean unless quoted ("true")empty: null— parsed as null unless quotedon: yes— parsed as boolean true (YAML 1.1 compatibility)code: 01234— parsed as octal in some parsers; quote to be safe
Strings that contain special characters (colons, hashes, leading/trailing whitespace, newlines, leading dashes) also need quoting. HopConvert applies quoting automatically using these rules. Toggle "Quote all strings" in settings if you want every string to be quoted explicitly — useful for diff stability and for users unfamiliar with YAML's ambiguity rules.
Multi-line strings
JSON has no real multi-line string type — embedded newlines must be escaped as \n. YAML supports two block scalar styles:
- Literal (
|): Newlines are preserved exactly. Best for code, configuration blobs, and any text where formatting matters. - Folded (
>): Newlines become spaces, except for blank lines which become single newlines. Best for prose where you'd otherwise use one long line.
When converting JSON, the converter can't know which style you want (the JSON doesn't encode the difference), so it defaults to literal (|) for any string containing a newline. You can change the default in settings or by post-processing the file.
Anchors and aliases
YAML has a feature JSON lacks: anchors (&name) and aliases (*name). An anchor marks a value for reuse; an alias refers back to it. This is useful for DRY configurations:
defaults: &defaults
retries: 3
timeout: 30
production:
<<: *defaults
host: prod.example.com
staging:
<<: *defaults
host: staging.example.com
JSON has no equivalent, so converting a YAML file with anchors to JSON will inline the values (losing the DRY structure). Converting JSON to YAML can't create anchors automatically — the input has no concept of "this is the same as that." If you need anchors, add them by hand after the conversion.
Kubernetes conventions
Kubernetes uses YAML 1.2 with a few conventions worth knowing:
- 2-space indent. Always. Tools like
kubectl applyandhelm installdon't care, but humans reading the file do. - Lowercase keys.
apiVersion,kind,metadata,spec. The schema is case-sensitive. - apiVersion first, then kind, then metadata, then spec, then status. Most YAML sorters will reorder keys to this convention; if yours doesn't, do it by hand.
- Strings with template syntax (
{{ .Values.foo }}) should be quoted to avoid YAML's type-coercion rules interpreting.Values.fooas a number. - Multi-document YAML (multiple
----separated documents in one file) is common for k8s manifests. The converter doesn't split or merge these — one JSON document becomes one YAML document.
Common edge cases
Most JSON-to-YAML conversions are straightforward, but a few patterns are worth knowing about:
- Empty objects and arrays: Emitted as
{}and[](flow style). This is the most portable representation across parsers. - Empty strings: Emitted as
""(quoted) to distinguish them from null and to make the column width obvious in editors. - Unicode: Preserved as-is. YAML is UTF-8 by default, so emoji and non-Latin characters round-trip cleanly.
- Very long strings: The converter doesn't wrap them. If you need a hard wrap, post-process the output (or use YAML's folded scalar style).
- Numbers that look like dates:
20241231stays a number."2024-12-31"stays a string. YAML 1.2 doesn't auto-parse dates (that's a YAML 1.1 quirk). - Trailing whitespace in strings: Preserved. YAML parsers handle this correctly; some text editors may strip it on save.
Frequently asked questions
Everything you need to know about converting JSON to YAML with HopConvert.
What is a JSON to YAML converter?
Is HopConvert free to use?
What is YAML used for?
Is YAML 1.2 supported?
How are keys sorted?
Does the converter add quotes around strings?
Can I convert a Kubernetes manifest JSON to YAML?
What about multi-line strings?
Is my JSON data private?
Can I open the YAML in my editor?
Turn your JSON into YAML
Free, instant, and private — your JSON never leaves this tab.