How to Convert JSON to YAML (and Back)
March 22, 2026 · 5 min read
JSON and YAML are two of the most popular data serialization formats. If you work with configuration files, APIs, or DevOps tools, you'll inevitably need to convert between them.
In this guide, you'll learn the key differences between JSON and YAML, when to use each, and how to convert between them — with examples and a free online converter.
JSON vs YAML: Key Differences
| Feature | JSON | YAML |
|---|---|---|
| Syntax | Braces and brackets | Indentation-based |
| Comments | Not supported | Supported (#) |
| Readability | Good for machines | Great for humans |
| Data types | Strings, numbers, booleans, null, arrays, objects | Same + dates, timestamps, multi-line strings |
| Common use | APIs, package.json, tsconfig | Docker Compose, Kubernetes, Ansible, CI/CD |
| Strictness | Very strict (quotes required) | More flexible (quotes optional) |
The Same Data in JSON and YAML
JSON
YAML
The YAML version is shorter and arguably easier to scan. This is why YAML is the go-to format for configuration files like docker-compose.yml, .github/workflows/*.yml, and Kubernetes manifests.
How to Convert JSON to YAML
Method 1: Online Converter (Instant)
The fastest way — paste your JSON and get YAML instantly:
Paste JSON, get clean YAML. Runs in your browser — nothing leaves your device.
Open JSON to YAML ConverterMethod 2: Command Line with Python
Method 3: Command Line with yq
Method 4: In Node.js
How to Convert YAML to JSON
Going the other direction? Use the YAML to JSON converter or the command-line methods above in reverse.
Paste YAML, get formatted JSON.
Open YAML to JSON ConverterCommon Gotchas
- YAML indentation matters — use spaces, never tabs. Most tools use 2-space indentation.
- Unquoted strings can be tricky — yes, no, true, false, and null are interpreted as booleans/null in YAML, not strings. Quote them if you mean the literal string.
- Multi-line strings — YAML supports | (literal block) and > (folded) for multi-line strings. JSON requires \n escapes.
- Comments are lost — when converting YAML to JSON, all comments (#) are stripped since JSON doesn't support them.
When to Use Which
- Use JSON for APIs, data interchange, and any context where strict parsing is important (package.json, tsconfig.json)
- Use YAML for configuration files that humans read and edit frequently (Docker Compose, Kubernetes, GitHub Actions, Ansible)
Related Tools
- JSON to YAML Converter
- YAML to JSON Converter
- JSON Formatter — pretty-print and validate JSON
- JSON Validator — check if your JSON is valid before converting