I am trying to strip a substring from an array of strings; this array is obtained as a key set from a map. Some example incoming data:
{
"appOneVersion": "1.0",
"appTwoVersion": "1.0",
"appThreeVersion": "1.0"
}
First I'm extracting the key set and making lower case which works:
$ jq -r 'with_entries( .key |= ascii_downcase) | keys' example.json
[
"apponeversion",
"appthreeversion",
"apptwoversion"
]
and then I'm attempting to strip the version part of each element with sub("version$"; "") however I'm not quite understanding how to make it iterate over the array instead of sub trying to operate on the array as a whole:
$ jq -r 'with_entries( .key |= ascii_downcase) | keys | sub("version$"; "")' example.json
jq: error (at example.json:5): array (["apponever...) cannot be matched, as it is not a string