Reputation: 31
I have multiple JSON files with a person's age and I want to match specific ages using regex, however, I cannot be able to match even a single integer in a file.
I can select age using following jq
,
jq -r .details.Age
I can match Name
using following jq
,
jq -r 'select(.details.Name | match("r.*"))'
But when I try to use test
or match
with Age
I get following error,
jq -r 'select(.details.Age | match(32))'
jq: error (at <stdin>:6): number not a string or array
Here is code,
{
"details": {
"Age": 32,
"Name": "reverent"
}
}
I want to be able to match Age
using jq
something like this,
jq -r 'select(.details.Age | match(\d))'
Upvotes: 0
Views: 359
Reputation: 116720
Your .Age value is a number, but regexes work on strings, so if you really want to use regexes, you would have to transform the number to a string. This can be done using tostring
, but please remember that the tostring
representation of a JSON number might not always be what you think it will be.
–––
p.s. That should be match("\\d")
Upvotes: 1