Given the data
{
"abc1": 0,
"abc2": 1,
"xyz1": 100
}
How can I get only the first two values, based on the fact that they start with 'abc'?
My first instinct was to use keys() and values(), but there is no zip() to put them back together.
Also, there is no .key or .value on a hash entry to look at one or the other to use with startswith().
There is also no facility to transform a hash into a list of two-tuples, either; to_array() "returns a one element array containing the passed in argument", which does not help at all.
In jq I was able to get it with
$ jq 'to_entries | map(select(.key |startswith("abc")))' /tmp/asdf.json
[
{
"key": "abc1",
"value": 0
},
{
"key": "abc2",
"value": 1
}
]
Note that the output format is immaterial to me; I can reformat it later. What I need is the selecting behavior.