From 2bab6385bdccf9e17ac5d3ae28e97b541417c2ca Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Thu, 10 Nov 2022 10:18:08 +1100 Subject: [PATCH] Added set path example --- operators/path.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/operators/path.md b/operators/path.md index 30c910b3..2ac89c16 100644 --- a/operators/path.md +++ b/operators/path.md @@ -122,6 +122,31 @@ a: b: things ``` +## Set path to extract prune deep paths +Like pick but recursive. + +Given a sample.yml file of: +```yaml +parentA: bob +parentB: + child1: i am child1 + child2: i am child2 +parentC: + child1: me child1 + child2: me child2 +``` +then +```bash +yq '(.parentB.child2, .parentC.child1) as $i ireduce({}; setpath($i | path; $i))' sample.yml +``` +will output +```yaml +parentB: + child2: i am child2 +parentC: + child1: me child1 +``` + ## Set array path Given a sample.yml file of: ```yaml