Why my jq treats null as a proper value while parsing json via jq
In the comment, you seem to indicate that there is one value of $dbname
, so the following should help:
dbname=phx4fo
CRSOUT=input.json
jq -r --arg dbname "$dbname" '(.[$dbname] // empty) |.db_sid_list' "$CRSOUT"
With your sample JSON, the above results in:
phx4fo1,phx4fo2
Presumably you will want to split on the comma, which can be done within the same jq query, e.g. by modifying it to:
(.[$dbname] // empty) | .db_sid_list/"," | .[]
By the way, if you are going to use read -a
, then you will need to understand shell arrays, and modify your shell script accordingly. I would suggest you break down your problem into small pieces that you can solve independently, so that it will be easier to construct a complete solution.