YAML to JSON Converter — multi-document and all
Paste YAML and get clean JSON. Anchors, several documents in one file, and tags are all handled. It runs in your browser, so a manifest never touches a server.
What is a YAML to JSON converter?
A YAML to JSON converter takes a YAML document and produces an equivalent JSON file. The two formats represent the same data structures — objects, arrays, strings, numbers, booleans, null — with different syntax. YAML is more human-friendly with its indentation and minimal punctuation; JSON is more machine-friendly with its explicit braces and quotes. The converter lets you move between them losslessly.
For example, this YAML:
name: web-server
replicas: 3
image: nginx:1.25
ports:
- 80
- 443
environment:
DOMAIN: example.com
DEBUG: false
becomes this JSON:
{
"name": "web-server",
"replicas": 3,
"image": "nginx:1.25",
"ports": [80, 443],
"environment": {
"DOMAIN": "example.com",
"DEBUG": false
}
}
The data is identical. YAML's indentation becomes JSON's braces and brackets; YAML's plain strings become JSON's quoted strings. The conversion is total and lossless for the six types both formats share.
How to convert YAML to JSON in 3 steps
Most conversions take less than a minute. No login, no upload to a server, no installation.
-
Paste or upload
Drop a
.yamlor.ymlfile into the upload zone, or paste YAML text. Multi-document files (separated by---) are supported. -
Configure
Open the settings cog to choose the JSON indent (2 or 4 spaces), whether to pretty-print or minify, and how to handle multi-document YAML.
-
Copy or download
Click Copy JSON to put the result on your clipboard, or Download JSON to save a
.jsonfile.
Built for the YAML you actually have
Real YAML uses anchors, multi-doc files, block scalars, and custom tags. HopConvert handles all of it via js-yaml, the reference parser.
Anchors & aliases
YAML anchors (&name) and aliases (*name) are inlined automatically. The same value appears wherever it was referenced.
Multi-document YAML
Files with multiple ----separated documents parse as a JSON array. Each document becomes one element.
Block scalars preserved
Literal (|) and folded (>) block scalars convert to JSON strings with their newlines kept exactly as specified.
Browser-only privacy
Parsing happens in your browser via the js-yaml library. Nothing is uploaded, logged, or stored on our servers.
Full YAML 1.2
Powered by js-yaml 4.1, the reference YAML parser. Supports tags, type coercion, and the complete 1.2 specification.
Live preview
The result panel updates as you type. See exactly what your JSON will look like before downloading.
YAML vs JSON: what's the difference?
Both formats store structured data, but they're designed for different jobs.
| Aspect | YAML | JSON |
|---|---|---|
| Syntax | Indentation, colons, dashes | Braces, brackets, commas, quotes |
| Best for | Configuration files, human editing | APIs, data interchange, machine-to-machine |
| File size | Larger (indentation is significant) | Smaller (less whitespace) |
| Human readability | High (clean, scannable) | Moderate (visual noise) |
| Comments | # comments | Not supported |
| References | Anchors (&) and aliases (*) — simple | JSON Pointer (complex) |
| Multi-line strings | Literal block (|) or folded (>) | Requires \n escapes |
| Standard | YAML 1.2 (no RFC) | RFC 8259 |
When teams reach for YAML to JSON
YAML is everywhere in modern infrastructure. The conversion unlocks all of it for JSON-based tools.
API testing
Send a YAML config to a JSON-only API by converting it first. Useful for legacy systems that pre-date YAML adoption.
Frontend data binding
JavaScript apps consume JSON. Convert a YAML config to JSON and fetch it from a static file in your build pipeline.
MongoDB import
Use mongoimport with a converted YAML to seed a collection. Faster than typing JSON by hand.
Configuration diff
JSON diffs are easier to read than YAML diffs in some tools. Convert both files and use a JSON diff viewer.
Static site generators
Many SSGs (Jekyll, Hugo, Astro) accept YAML or JSON for data files. Convert to JSON if your tooling prefers it.
Kubernetes debugging
Pipe kubectl get -o yaml through the converter for a clean JSON view in your editor or API client.
YAML to JSON: the complete guide
Everything you need to know about the YAML format, the conversion rules, and how to handle real-world edge cases.
YAML syntax basics
YAML uses three structural markers: indentation for hierarchy, colons for key-value pairs, and dashes for list items. A simple document:
name: web-server
replicas: 3
image: nginx:1.25
ports:
- 80
- 443
labels:
app: web
tier: frontend
Two-space indent is the convention; three or four is legal but unusual. Tabs are forbidden in YAML — only spaces. The colon after a key must be followed by a space. A dash at the start of a line introduces a list item.
YAML is also a strict superset of JSON: any valid JSON document is also valid YAML. That's what makes the conversion lossless.
YAML's type system
YAML 1.2 has six core scalar types plus a few extras:
- Mappings (objects): key-value collections, written as nested indentation. Become JSON objects.
- Sequences (arrays): ordered lists, written with dashes. Become JSON arrays.
- Strings: either quoted (with single or double quotes) or plain (no quotes, when unambiguous). Become JSON strings.
- Integers: 42, -17, 0x2A (hex). Become JSON numbers.
- Floats: 3.14, 1.5e10, .inf, .nan. Become JSON numbers (except .nan which becomes a string).
- Booleans: true / false (YAML 1.2 canonical). Yes / no / on / off are YAML 1.1 and not supported in 1.2. Become JSON booleans.
- Null: null, ~, or empty. Become JSON null.
When parsing, js-yaml infers the type based on the value's syntax. A string that looks like a number (e.g., "42" with quotes) stays a string; an unquoted 42 becomes a number. If your YAML has type-coercion bugs (e.g., a zip code 01234 becoming octal), quote it in the source YAML to force string interpretation.
Anchors and aliases
YAML anchors (&name) mark a value for reuse; aliases (*name) refer back to it. This is useful for DRY configuration:
defaults: &defaults
retries: 3
timeout: 30
production:
<<: *defaults
host: prod.example.com
staging:
<<: *defaults
host: staging.example.com
When this YAML is converted to JSON, the alias is inlined — both production and staging get their own copy of {retries: 3, timeout: 30}. JSON has no concept of shared references, so this is the only sensible behaviour. The result is larger than the YAML, but valid JSON.
Multi-document files
A single YAML file can contain multiple documents separated by ---:
---
apiVersion: v1
kind: Service
metadata:
name: frontend
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend
This is common in Kubernetes for combining related resources. The converter parses each document and produces a JSON array, where each element is one document. Single-document YAML produces a single JSON object, not an array. Toggle "always wrap in array" in settings to force a consistent shape regardless of input.
Multi-line strings
YAML has two block scalar styles for multi-line strings:
- Literal (
|): Newlines are preserved exactly. Best for code, configuration blobs, and any text where line breaks matter. - Folded (
>): Line breaks become spaces, except blank lines which become single newlines. Best for prose paragraphs.
Both styles convert to JSON strings with their newlines preserved as-is. The | style keeps \n separators; the > style folds them into spaces. JSON doesn't distinguish between the two, so the output reflects what your YAML specified.
Tags and custom types
YAML allows you to explicitly tag a value's type with a !! prefix or custom ! prefix:
name: !!str 42
date: !!timestamp 2024-12-31
binary: !!binary |
R0lGODlhDAAMAIQAAP//9/X
Standard tags (!!str, !!int, !!bool, !!null, !!float, !!timestamp, !!binary) are honoured. Binary data is base64-decoded to a string. Timestamps become ISO 8601 strings (JSON has no native timestamp type). Custom tags produce a parse error — if you need them, register them in the settings panel or simplify the YAML.
Common edge cases
Most YAML-to-JSON conversions are straightforward, but a few patterns are worth knowing about:
- Norway problem: The country code "NO" is interpreted as boolean false in YAML 1.1. YAML 1.2 fixed this; modern parsers (including js-yaml 4.x) read it as a string. If you're stuck on YAML 1.1, quote "NO" in the source.
- Octal numbers:
01234in YAML 1.1 is octal (1234 decimal). In YAML 1.2, leading zeros are just integers. Quote if you need the literal string. - Trailing whitespace: Preserved in plain strings but stripped in block scalars. Quote if you need exact preservation.
- Empty values:
key:(no value) is null.key: ""is an empty string.key: ~is also null. They look the same in YAML but mean different things in JSON. - Comments and directives: Comments (
# ...) are stripped. YAML directives (%YAML 1.2) are honoured.---at the start of a file is a document start marker (not data); it's stripped during parsing. - Reserved keys at the top level: YAML 1.1's "Norway problem" and similar quirks are gone in 1.2. js-yaml 4.x is strict 1.2 — if you have older YAML, you may see errors that weren't errors before.
The same job, the way you need it
Free tools for the specific version of this conversion you are actually doing.
YAML to JSON for Kubernetes
Multi-document manifests, anchors and all - plus the yq and kubectl commands.
Frequently asked questions
Everything you need to know about converting YAML to JSON with HopConvert.
What is a YAML to JSON converter?
Is HopConvert free to use?
What happens to YAML anchors and aliases?
Does the converter handle multi-document YAML?
Is YAML 1.2 supported?
How are multi-line strings handled?
Can I convert a Kubernetes manifest YAML to JSON?
What about YAML tags and custom types?
Is my YAML data private?
Can I open the JSON in my editor?
Turn your YAML into JSON
Free, instant, and private — your YAML never leaves this tab.