I want to know if this filter will be able to retrieve data from the JSON data structure. For instance:
% Name=steve
% jq -j --arg Name "$Name" '.[]|select(.user == $Name)|.value' <<<'
[
{"user":"steve", "value":false},
{"user":"tom", "value":true},
{"user":"pat", "value":null},
{"user":"jane", "value":""}
]'
false
% echo $?
0
Note. successful results can include booleans, nulland even an empty string.
% Name=mary
% jq -j --arg Name "$Name" '.[]|select(.user == $Name)|.value' <<<'
[
{"user":"steve", "value":false},
{"user":"tom", "value":true},
{"user":"pat", "value":null},
{"user":"jane", "value":""}
]'
% echo $?
0
If the filter does not extract data from the JSON data structure, I need to know this. I would prefer the filter to return a non-zero return code.
How would I decide whether a selector is successfully retrieving data from a JSON data structure or not retrieving data?
Important: The above filter is just an example, the solution should work for any jq filter.
Note. Bash 4.2+ evaluation environment.