Intention: Need to iterate the each item in json array using jq and proccess seperately
api returns data in form
{
"name": [
{
"first": "first",
"class": false,
"type": "B"
},
{
"first": "second",
"class": false,
"type": "B"
},
{
"first": "third",
"class": false,
"type": "A"
}
]
}
And i am able to parse it as
data=`curl http://some.ur;l`
echo "$data" | jq -rc '.name[] | select(.type=="B") | .class=true'
it returns data as
{"first": "first","class": true, "type": "B"}
{"first": "second", "class": true, "type": "B"}
Now i want to proccess these two outputs in such a way so that i can make a PUT call for each of them . I tried to learn some concepts of xargs but could not make it done
I piped the output to | xargs -n1 but it removed all the quotes from the string
"name", in the other you have.names. Make sure your example is internally consistent.echo $datais itself buggy and can corrupt your strings. Always use quotes, as in,echo "$data", and ideally useprintf(printf '%s\n' "$data"). See I just assigned a variable, butecho $variableshows something else and Why is printf better than echo?jq -cto make each item evaluate to one line of output, and a BashFAQ #1while readloop to iterate over those lines.cmdtag is for Microsoft Windows cmd.exe questions.jqinstead of having the same one that does theselectalso setclass=True?