YAML and JSON: the same data, two notations
YAML is the configuration language of Docker Compose, Kubernetes, GitHub Actions, Ansible and countless apps. It describes the same structures as JSON, nested maps, lists and values, but uses indentation instead of braces and allows comments, which makes it pleasant to write by hand and easy to get subtly wrong.
This converter turns YAML into JSON so you can see exactly how a file is understood, and turns JSON into tidy YAML. It handles the everyday subset: key: value pairs, nesting by indentation, lists with dashes, quoted strings, numbers, booleans and null.
How to use it
- Choose YAML to JSON or JSON to YAML.
- Paste your document or load a file.
- Read the output. When converting YAML, check that every value has the type you meant, for example a number rather than a string.
- Copy the result into your code or configuration.
Example: a small service config
server: host: example.com port: 8080 tls: true users: - ada - linus
{
"server": {
"host": "example.com",
"port": 8080,
"tls": true
},
"users": [
"ada",
"linus"
]
}Indentation creates the nesting, the dashes create a list, and 8080 and true become a number and a boolean.
The type traps
YAML guesses types from how a value looks. In YAML 1.1, still used by many tools, yes, no, on and off are booleans, which is how the country code NO for Norway famously turned into false. Version numbers such as 1.10 become the number 1.1, and a postal code like 01234 can lose its leading zero.
The safe habit is to quote any string that could look like something else. When this tool writes YAML from JSON, it quotes such strings automatically, so "yes", "01234" and "1.10" stay strings in every parser.
Indentation rules
YAML forbids tabs for indentation; use spaces, consistently, usually two per level. Items of a list and keys of a map at the same level must line up exactly. Most YAML errors are one space too many or too few, so converting to JSON is a quick way to see which level a key really ended up on.
What this tool does not cover
Full YAML is large. Anchors and aliases (&default and *default), multi-line block strings with | and >, multiple documents separated by ---, flow-style maps like {a: 1} and custom tags are outside the supported subset. For files that use them, a full parser such as the one in your programming language is the right tool.
Questions
Are comments kept?
No. JSON has no comments, so they are dropped when converting YAML to JSON and cannot be recreated in the other direction.
Is all JSON valid YAML?
Since YAML 1.2, practically yes: JSON was made a subset of YAML. The reverse is not true.
Is my file uploaded?
No. Parsing and conversion happen in your browser, so configuration with internal hostnames stays on your machine.