One way would be to convert all keys to lower-case as a default format and extract the key name of your choice (inspired from this peak's answer)
with_entries( .key |= ascii_downcase ).key
The .key
inside with_entries(..)
is not to be confused with the key name of your choice, because that is the default name for all key-names when using the family of *entries functions in jq
- with_entries
, to_entries
and from_entries
If your keys are nested inside other objects, one would would be walk
through the entire JSON to recursively rename the keys and fetch the field of your choice
def recursive_key_rename:
walk( if type == "object" then with_entries( .key |= ascii_downcase ) else . end);
recursive_key_rename | .key.anotherkey
See jq-play demo