Merge lists with same key into a single list #2073
Answered
by
mikefarah
karamellpelle
asked this question in
Q&A
-
Consider the following YAML document: train:
locomotive:
fruits:
- banana
- pear
- apple
wagon-1:
fruits:
- strawberry
- apricot
wagon-2:
fruits:
- papaya
- plum
- lime
fruits:
- orange
- lemon
airplane:
fruits:
- mango
- pineapple
- lemon
- banana
- grapefruit
- kiwi
- clementine The key The closest to a solution I've gotten is this question, but still not the same. I'm going to use yq in a patch for a vim plugin. |
Beta Was this translation helpful? Give feedback.
Answered by
mikefarah
Jun 29, 2024
Replies: 1 comment 1 reply
-
Sure:
Explanation:
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
karamellpelle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sure:
Explanation:
.. | select(has("fruits"))
finds all the nodes that has a child 'fruits'.fruits
gets the array.[]
splats the array into its component fruit strings