Convert a YAML (yml) document into JSON to see the structure that indentation hides and the actual type each value was parsed as. Anchors and aliases are expanded into real values, and multiple documents separated by --- are collected into an array.
It is especially handy for catching classic YAML mistakes: a value attached to the wrong parent because of one missing space, or version: 1.10 silently becoming the number 1.1.
YAML box, or drop the file onto it.Result to see whether each value became a string, number or boolean, and copy it if you need it.name: ci
on:
push:
branches: [main]
defaults: &node
runs-on: ubuntu-latest
timeout-minutes: 10
jobs:
test: *node
{
"name": "ci",
"on": {
"push": {
"branches": [
"main"
]
}
},
"defaults": {
"runs-on": "ubuntu-latest",
"timeout-minutes": 10
},
"jobs": {
"test": {
"runs-on": "ubuntu-latest",
"timeout-minutes": 10
}
}
}The GitHub Actions on: key stays the string key "on", because this tool parses with YAML 1.2 rules. The block defined with the &node anchor is expanded in place of *node.
yes, on and off stay strings, and only true/True/false become booleans.~ and empty values become null; hex 0x1F and octal 0o17 become numbers.&anchors and *aliases are resolved to the referenced values.| and folded > block scalars are turned into strings with YAML's newline rules applied.----separated documents become a JSON array; a single document is output as its own value.If env under containers is indented one level too shallow, it silently attaches to another field and you only find out at apply time. In JSON, the braces show exactly which object it belongs to.
For a script or front-end bundle where adding a YAML parser is overkill, convert the config once and use it as import config from './config.json'.
An OpenAPI document written in YAML is easier to query with JSONPath or jq once converted, for example to pull out the schema at a specific path.
<<: *defaults) are applied: the anchored mapping's keys are copied in, and keys written next to << override them. A YAML 1.2-only parser would keep << as a plain key, so results can differ from such tools.2024-01-01 stay strings rather than becoming Date values..inf and .nan have no JSON representation and become null.on and yes as true, so results from Python may differ.on shown as "on" instead of true?In YAML 1.2 the only booleans are true and false, so on is an ordinary string, which is also how GitHub Actions reads the key. Python's PyYAML follows 1.1 and turns it into a True key, so watch out when parsing workflows from scripts.
version: 1.10 comes out as 1.1.Unquoted 1.10 is a number in YAML, and 1.10 equals 1.1. To keep a version string, quote it in the source YAML as "1.10".
Each ----separated document becomes an array element in order, so a multi-resource file used with kubectl apply -f yields an array of resources.