JSON and YAML Cheat Sheet
Sat, Oct 22, 2022
One-minute read
Shell Terminal
Access JSON properties
| jq .
| jq ".prop1,prop2.index,.[0]"
| jq ".[] | .location"
| jq ".[] | select(.location == "Stockholm")"
| jq "to_entries[]"
Convert yaml to json
yq -o=json . <yaml-file> > <json-file>
Convert json to yaml
yq -o=json . <yaml-file>
JavaScript
Pretty print in JS
console.log(JSON.stringify(json, null, 4))