From 4519796d7aed204636e449b710326c268dec4110 Mon Sep 17 00:00:00 2001 From: Kim Do-hyeong Date: Mon, 9 Nov 2026 10:52:58 +0900 Subject: [PATCH] Add yq cheatsheet Added usage examples for the yq command to handle YAML and JSON files. --- yq | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 yq diff --git a/yq b/yq new file mode 100644 index 0000000..f409f3c --- /dev/null +++ b/yq @@ -0,0 +1,40 @@ +--- +syntax: bash +tags: [ yaml, json ] +--- + +# To read a value from a YAML file: +yq '.a.b' + +# To read a value from standard input: +cat | yq '.a.b' + +# To update a value in place: +yq -i '.a.b = "value"' + +# To convert YAML to JSON: +yq -o=json '.' + +# To convert JSON to YAML: +yq -p=json -o=yaml '.' + +# To iterate over the elements of a list: +yq '.[]' + +# To select list elements matching a condition: +yq '.[] | select(.name == "")' + +# To merge two YAML files (later files override earlier ones): +yq eval-all '. as $item ireduce ({}; . * $item)' + +# To evaluate an expression across all documents of all files at once: +yq eval-all '' + +# To get the length of a list: +yq '.list | length' + +# To list the keys of a map: +yq 'keys' + +# To extract YAML front-matter from a markdown file: +yq --front-matter=extract '.'