I have the following test.json
{"type":"RECORD","record":{"key_A": "apples","key_B":"bananas"}}
{"type":"RECORD","record":{"key_A": "apples","key_B":"oranges"}}
Then see the following command and output.
cat test.json | jq 'select(.record.key_B="oranges")'
{
"type": "RECORD",
"record": {
"key_A": "apples",
"key_B": "bananas"
}
}
{
"type": "RECORD",
"record": {
"key_A": "apples",
"key_B": "oranges"
}
}
I wish it would only output the record which match the select – the ones where .record.key_B = oranges so only the first record. How can I do this?
>Solution :
= is an assignment operator. == is an equality-comparison operator.
You want select(.record.key_B == "oranges").