mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-24 14:45:39 +00:00
Improved set path example
This commit is contained in:
parent
22f376bbfd
commit
fdad478684
@ -123,7 +123,7 @@ a:
|
|||||||
```
|
```
|
||||||
|
|
||||||
## Set path to extract prune deep paths
|
## Set path to extract prune deep paths
|
||||||
Like pick but recursive.
|
Like pick but recursive. This uses `ireduce` to deeply set the selected paths into an empty object,
|
||||||
|
|
||||||
Given a sample.yml file of:
|
Given a sample.yml file of:
|
||||||
```yaml
|
```yaml
|
||||||
@ -137,7 +137,8 @@ parentC:
|
|||||||
```
|
```
|
||||||
then
|
then
|
||||||
```bash
|
```bash
|
||||||
yq '(.parentB.child2, .parentC.child1) as $i ireduce({}; setpath($i | path; $i))' sample.yml
|
yq '(.parentB.child2, .parentC.child1) as $i
|
||||||
|
ireduce({}; setpath($i | path; $i))' sample.yml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```yaml
|
```yaml
|
||||||
|
@ -90,9 +90,9 @@ var pathOperatorScenarios = []expressionScenario{
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
description: "Set path to extract prune deep paths",
|
description: "Set path to extract prune deep paths",
|
||||||
subdescription: "Like pick but recursive.",
|
subdescription: "Like pick but recursive. This uses `ireduce` to deeply set the selected paths into an empty object,",
|
||||||
document: documentToPrune,
|
document: documentToPrune,
|
||||||
expression: `(.parentB.child2, .parentC.child1) as $i ireduce({}; setpath($i | path; $i))`,
|
expression: "(.parentB.child2, .parentC.child1) as $i\n ireduce({}; setpath($i | path; $i))",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"D0, P[], (!!map)::parentB:\n child2: i am child2\nparentC:\n child1: me child1\n",
|
"D0, P[], (!!map)::parentB:\n child2: i am child2\nparentC:\n child1: me child1\n",
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user