I recently discovered jqjq and grongron.
For my use case, gron is sufficient, but I am a little worried by lack of development. There are some bugs that have not been addressed in an year, while I see that jq is actively developed.
So I would like to emulate gron using jq. I suspect it is not too difficult, but my knowledge of jq is limited.
As an example, I'd like to use jq to obtain this output:
T424f7496c3a01 -14889.86
demo -15030.785
from this input:
{
"T424f7496c3a01": {
"remaining": -14889.86,
"ts": 136572.504
},
"demo": {
"remaining": -15030.785,
"ts": 0.515
}
}
I have come up with this jq script which does it:
jq -r '[keys,([.[]|.remaining|round|"\t"+tostring])]|transpose|.[]|add'
but it is much less readable than
gron | fgrep '.remaining = '
which produces
json.T424f7496c3a01.remaining = -18079.105;
json.demo.remaining = -18220.029;
that can be easily parsed using an IFS=" .=;" read loop in bash.
So I am asking a question of long-term maintainability: is there a simple script for jq that can give me something easily parseable in bash? I fear that using the jq script above in one month I will have no idea how it works...
P.S.
The answer I chose answers the above query. I hoped there would be an equally simple answer for the query mentioned in the title, i.e. emulating gron by using jq. In fact, the comment below by @Kusalananda references How to print path and key values of JSON file, where the chosen answer is near enough to a gron emulation. Unfortunately, that solution is too complex to satisfy my long-term maintenance and readablity objectives.