Reputation: 608
I have a larger dataset, but here is a sample of my json file.
{"units": {
"1000000043579e28": {
"1_hostname": "unit-a",
"3_lastCheckIn": "08/31/21 16:00",
"screensProcesses": [
"file1",
"file2" ]},
"10000000553ff4cd": {
"1_hostname": "unit-b",
"3_lastCheckIn": "08/31/21 16:00",
"screensProcesses": [
"file1" ]}
}}
I would like to use the jq binary in linux. I'm trying to do 2 queries.
Upvotes: 0
Views: 455
Reputation: 10865
You might want to separate this into two questions since #1 is a relatively simple select while #2, dealing with time calculations is a topic in its own right. In any case, for #1 you can use with_entries
to convert units
to series of maps with key
and value
fields, operate on those with select
and convert back again.
$ jq '{"units": .units | with_entries(select(.value."screensProcesses" | length < 2))}' file.json
{
"units": {
"10000000553ff4cd": {
"1_hostname": "unit-b",
"3_lastCheckIn": "08/31/21 16:00",
"screensProcesses": [
"file1"
]
}
}
}
Upvotes: 1