I'm trying to use the JQ command to filter a json object to selectively extract keys. Here's a sample object that I've placed in file x.txt:
{"activities" : {"-KSndgjqvmQkWVKHCpLh" : {"create_device" : "...","stop_time_utc" : "2016-11-01T23:08:08Z" },"-KSoBSrBh6PZcjRocGD7" : {"create_device" : "..." },"-KSptboGjo8g4bieUbGM" : {"create_device" : "...","stop_time_utc" : "2017-01-17T23:08:08Z" } }}
The following command can extract all of the activity keys:
cat x.txt | jq '.activities | keys'["-KSndgjqvmQkWVKHCpLh","-KSoBSrBh6PZcjRocGD7","-KSptboGjo8g4bieUbGM"]
I've been googling and experimenting for a few hours trying to filter the object to select only the activity entries that have a stop_time_utc value, and use something like a "select(.stop_time_utc | fromdateiso8601 > now)" to only pick activities that have expired. For example, I'd like to use filters to create an array from the sample object with only the one relevant entry:
["-KSndgjqvmQkWVKHCpLh"]
Is attempting this with the keys option the wrong route? Any ideas or suggestions would be much appreciated.