From 57e463963139895102edd33c77f50e6256e11485 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Fri, 6 Sep 2024 12:33:38 +1000 Subject: [PATCH] updating docs --- operators/kind.md | 7 +++++++ operators/pick.md | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/operators/kind.md b/operators/kind.md index 1f65dfbb..4583410c 100644 --- a/operators/kind.md +++ b/operators/kind.md @@ -1,3 +1,10 @@ +# Kind + +The `kind` operator identifies the type of a node as either `scalar`, `map`, or `seq`. + +This can be used for filtering or transforming nodes based on their type. + +Note that `null` values are treated as `scalar`. ## Get kind Given a sample.yml file of: diff --git a/operators/pick.md b/operators/pick.md index fbe9bd95..935a2232 100644 --- a/operators/pick.md +++ b/operators/pick.md @@ -26,6 +26,30 @@ myMap: cat: meow ``` +## Pick keys from map, included all the keys +We create a map of the picked keys plus all the current keys, and run that through unique + +Given a sample.yml file of: +```yaml +myMap: + cat: meow + dog: bark + thing: hamster + hamster: squeak +``` +then +```bash +yq '.myMap |= pick( (["thing"] + keys) | unique)' sample.yml +``` +will output +```yaml +myMap: + thing: hamster + cat: meow + dog: bark + hamster: squeak +``` + ## Pick indices from array Note that the order of the indices matches the pick order and non existent indices are skipped.