Skip to content

Change all keys in yaml file to lowercase #2306

Answered by mikefarah
0byt3 asked this question in Q&A

You must be logged in to vote

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.

yq '(.. | select(type == "!!map")) |= with_entries(.key |= downcase)' examples/data1.yaml

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

Replies: 1 comment 2 replies

You must be logged in to vote
2 replies
@mikefarah

@0byt3

Answer selected by 0byt3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants