I have a JSON file I'd like to filter by the ID field, and show the matching Body and Source fields.
Format of the JSON file to filter
[
{
"timestamp" : 1638550971085,
"id" : "54f",
"body" : "Orange",
"source" : "827261"
},
{
"timestamp" : 1638550971096,
"id" : "54f",
"body" : "Apple",
"source" : "137261"
},
{
"timestamp" : 1638550971126,
"id" : "5da",
"body" : "Pear",
"source" : "1da61"
}
]
In this example I would like to filter where id = 54f and show the Timestamp (Unixtime converted to local time), Body and Source fields that match, ideally as shown below.
[Timestamp] Orange 827261
[Timestamp] Apple 137261
I have tried this command, but it is showing extra body / source fields outside of the SQL filter. It also adds a line break between printing the body and source, and ideally I'd like this printed on one line (tab separated). I also don't know how to convert the timestamp to localtime string.
more file.json | jq '.[] | select(.Id=="54f").body, .source'