I have the following windows.json
file
[{
"id":5178,
"pid":40345,
"app":"Alacritty",
"title":"Alacritty",
"frame":{
"w":880.0000,
"h":531.0000
}
},{
"id":5780,
"pid":44378,
"app":"Skim",
"title":"Brezis.pdf",
"frame":{
"w":980.0000,
"h":532.0000
}
},{
"id":5771,
"pid":44378,
"app":"Skim",
"title":"struct.pdf",
"frame":{
"w":980.0000,
"h":532.0000
}
}]
and I'd like to do three things:
1) get the elements whose app is "Skim" and store them in a variable;
2) count how many elements there are with the app "Skim", and store that in a variable.
3) get the title
s of all the elements with the app "Skim", and store them in a list.
I can do the first two in a shell with
$ Skim_windows=$(cat ~/windows.json | jq -r ".[] | select(.app==\"Skim\")")
$ Skim_windows_count=$(echo $Skim_windows | jq -r ".id" | wc -l)
and I'm trying to replicate that inside a vim function. The code I currently have is
let Skim_windows = system("cat ~/windows.json | jq -r \".[] | select(.app==\\\"Skim\\\")\"")
let Skim_windows_count = system("echo ".shellescape(Skim_windows,1).(" | jq -r \".id\" | wc -l"))
which doesn't work, because if I echo Skim_windows_count
I get the error
parse error: Invalid numeric literal at line 2, column 0
I also have no idea how to get all the title
s and assign them to a list (in vim).