I have json string like this:
jstring='[{"userQuery":"select name from abc;","user":"abc"},{"userQuery":"select name from xyz;","user":"xyz"},{"userQuery":"select name from ppp;","user":"ppp"}]'
I wrote a simple for loop using jq to extract values but not getting the desired result.
for i in `echo $jstring | jq '.[] | [.user, .userQuery]'`; do echo ${i}; done
With the help of this line : echo $jstring | jq '.[] | [.user, .userQuery]'
. I am able to extract below info:
[ "abc", "select name from abc;"][ "xyz", "select name from xyz;"][ "ppp", "select name from ppp;"]
Now, I want two variable "user" & "query" for each array and store that info.
Eg: For [ "abc", "select name from abc;"] -- user: abc, query: "select name from abc" and store them.
I am not sure how to iterate over json using jq and get individual values and store them.