YAML to JSON Converter
Convert a YAML document into JSON with your preferred indentation and brace style.
Option 2: Or upload your YAML file
Ctrl + Enter
Result
YAML explained
YAML ("YAML Ain't Markup Language") is a human-friendly data serialization format widely used for configuration files (Docker Compose, Kubernetes, GitHub Actions, Ansible, OpenAPI…). Its data model is a superset of JSON: mappings (objects), sequences (arrays) and scalars. Structure is expressed by indentation with spaces (tabs are not allowed), which makes the files easy to read but also easy to break. This converter parses YAML 1.2 with the core schema and produces equivalent JSON.
YAML basics
| Concept | YAML | JSON equivalent |
|---|---|---|
| Mapping (object) | name: Alice age: 30 | {"name": "Alice", "age": 30} |
| Sequence (array) | - json - yaml | ["json", "yaml"] |
| Flow style (inline) | tags: [a, b]
point: {x: 1, y: 2} | {"tags": ["a", "b"], "point": {"x": 1, "y": 2}} |
| Scalars | str: hello quoted: "12" int: 42 float: 3.14 bool: true nothing: null also_null: ~ | Unquoted values are typed automatically: "12" stays a string, 42 becomes a number, true/false booleans, null and ~ become null. |
Multi-line: literal | | text: | line one line two | "line one\nline two\n" (line breaks kept) |
Multi-line: folded > | text: > folded into one line | "folded into one line\n" (line breaks become spaces) |
| Anchors & aliases | base: &defaults retries: 3 job: <<: *defaults name: build | The anchor &defaults names a node, *defaults reuses it and << merges it: {"base": {"retries": 3}, "job": {"retries": 3, "name": "build"}} |
| Comments | # a comment key: value # trailing comment | Dropped (JSON has no comments) |
| Multiple documents | --- a: 1 --- b: 2 | Each document separated by --- becomes an entry of a JSON array: [{"a": 1}, {"b": 2}] |
| Dates | released: 2024-05-01 | Timestamps are converted to ISO 8601 strings: "2024-05-01T00:00:00.000Z" |
Example
Input YAML:
server:
host: localhost
ports:
- 80
- 443
tls: true
motd: |
Welcome!
Enjoy your stay.
Output JSON:
{
"server": {
"host": "localhost",
"ports": [ 80, 443 ],
"tls": true,
"motd": "Welcome!\nEnjoy your stay.\n"
}
}
Common pitfalls
- Tabs are forbidden for indentation: use spaces (the parser reports the exact line and column of the problem).
- A value containing
:or starting with special characters (*,&,!,%,@,`,[,{,#) must be quoted. - In YAML 1.1
yes/no/on/offwere booleans; in YAML 1.2 (used here) they are plain strings. Quote version numbers such as1.10to keep them as strings. - Duplicate keys in a mapping are an error.