yaml-update step syntax for conditionally selecting objects from arrays #3080
Replies: 1 comment
-
Nothing that sophisticated is possible yet, but I'd like to get there.
The most important requirement when we first wrote that was that existing comments and formatting choices in the YAML file be preserved. We didn't readily find a library that could handle that. Kustomize has some stuff internally that may be useful for this purpose, but at the time, we couldn't really get it working. So we rolled our own lib for updating values in a YAML file, but for the narrow use of updating something like Now that we've generalized the |
Beta Was this translation helpful? Give feedback.
-
Quick question hopefully around how to use the yaml-update on selectors more complex than simple dot notation for objects.
Has anyone worked out the syntax for selecting a key in an object which is in an array?
I can select and replace it using yq on the terminal but using a yq path with a select component doesn't seem to work.
Given this example file:
How do I set the
something
value ifid
==a
?Here's the example using the yq CLI to achieve an update on a key in this way.
yq '(.example.nested[] | select(.id == "a") | .something) = "abc"' test.yaml example: nested: - id: a something: abc - id: b something: value
Beta Was this translation helpful? Give feedback.
All reactions