i am trying to read for a big json data structure and I get the message:
parse error: Invalid numeric literal at line 2, column 0
The command that I'm using is the next one:
n_rules=$(echo rulebase_list | jq '.total')
and the file has in the first hierarchy level a variable which is
"total" : 126
Do you know why im experiencing problems with that? I suppose that the problem is that 126 is a numeric value but what can I do?
Carefully check your script against the one you posted in the question. If they match then the answer is very easy.
There is no "total" : 126
in the string you pass to jq
because you pass it the output of echo rulebase_list
that is rulebase_list
.
What you probably wanted is to send to jq
the content of the rulebase_list
file and the tool for this is cat
:
n_rules=$(cat rulebase_list | jq '.total')
Alternatively (and faster) is to redirect the input of jq
from the file:
n_rules=$(jq '.total' < rulebase_list)
Or to specify the input file name as the last argument in the command line of jq
:
n_rules=$(jq '.total' rulebase_list)
Read more about jq
: https://stedolan.github.io/jq/manual/
You forgot to include $
in your script. Add it and it'll be fixed.
n_rules=$(echo $rulebase_list | jq '.total')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With