How JSON maps to YAML
JSON and YAML describe the same data model: mappings (JSON objects), sequences (JSON arrays) and scalars (strings, numbers, booleans and null). YAML 1.2 was designed so that every JSON document is also a YAML document, so conversion never loses information. The converter writes YAML in block style: each key on its own line, nesting shown by indentation, and list items marked with - .
| JSON | YAML |
|---|---|
{"name": "api", "port": 8080} | name: apiport: 8080 |
{"tags": ["a", "b"]} | tags: - a - b |
{"empty": {}, "none": []} | empty: {}none: [] |
{"v": null, "ok": true} | v: nullok: true |
{"code": "0755", "n": "123"} | code: "0755"n: "123" |
How to convert JSON to YAML
- Paste the JSON or open a
.jsonfile. It is validated first; errors are listed with line numbers and Fix JSON can repair common mistakes. - Choose 2 or 4 spaces and whether keys should be sorted.
- Click To YAML. Copy the result or download it as
data.yaml.
Example: a package manifest
{"name": "web", "version": "1.10", "scripts": {"build": "vite build"}, "private": true}
becomes
name: web
version: "1.10"
scripts:
build: vite build
private: true
The version stays quoted because an unquoted 1.10 would be read back as the number 1.1.
Why convert JSON to YAML?
- Configuration: Kubernetes, Docker Compose, GitHub Actions, GitLab CI, Ansible and OpenAPI files are usually written in YAML, while tools and APIs often emit JSON.
- Readability: no braces, fewer quotes and room for comments make YAML easier to review.
- Editing: adding a line to a YAML list does not require touching the line above, so diffs are smaller.
For the opposite direction use YAML to JSON; to tidy the YAML afterwards use the YAML formatter.