-
The syntax on how to recurse and then manipulate the key name is not clicking with me. yq -N -o yml '. | with_entries(.key |= downcase)' test.yml I have got this far: yq -N -o yml '(.. | select(type == "!!map")) | with_entries(.key |= downcase)' test.yml However it doesn't produce the correct results. file: key_one: "<password>"
key_two: "<username>"
KEY_three:
key_a:
Key_i: "val_three_a_i"
key_ii: "val_three_a_ii"
key_B:
key_i: "val_three_b_i"
key_I: "val_three_b_ii"
key_c:
key_i: "val_three_a_i"
key_I: "val_three_a_ii" output: key_one: "<password>"
key_two: "<username>"
key_three:
key_a:
Key_i: "val_three_a_i"
key_ii: "val_three_a_ii"
key_B:
key_i: "val_three_b_i"
key_I: "val_three_b_ii"
key_c:
key_i: "val_three_a_i"
key_I: "val_three_a_ii"
key_a:
Key_i: "val_three_a_i"
key_ii: "val_three_a_ii"
key_b:
key_i: "val_three_b_i"
key_I: "val_three_b_ii"
key_c:
key_i: "val_three_a_i"
key_I: "val_three_a_ii"
key_i: "val_three_a_i"
key_ii: "val_three_a_ii"
key_i: "val_three_b_i"
key_i: "val_three_b_ii"
key_i: "val_three_a_i"
key_i: "val_three_a_ii" |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You're very close, the reason you're getting that is because '..' expands to match all nodes - and then you are running the remaining expressions on that expansion. What you want to do is have the expansion as a LHS parameter of an update function, to just run an update on all the matches.
So now it finds all the maps, and for every map it will replace it with the calculation from with_entries. Going to add an example to the entries doc |
Beta Was this translation helpful? Give feedback.
You're very close, the reason you're getting that is because '..' expands to match all nodes - and then you are running the remaining expressions on that expansion. What you want to do is have the expansion as a LHS parameter of an update function, to just run an update on all the matches.
So now it finds all the maps, and for every map it will replace it with the calculation from with_entries.
Going to add an example to the entries doc