What I do:
RESPONSE_TEMPLATES=$(curl "https://maydomain.com/test) {
"templateId": "test",
"id": 1621030
}
{
"templateId": "test1",
"id": 5014
}
{
"templateId": "test3",
"id": 5015
}
echo $(${RESPONSE_TEMPLATES} | jq -r '.[]'| {templateId,id}')Problem is that I always get error: [{"id":1386084,"templateId":"test: command not found
I do not know how I should write 3 steps so that it will display this as a string and not use after ""test: " as command.
With your shown samples please try following jq code. Using -r option to enable raw-mode option of jq then in main block using select function to check if component .templateId is test if yes then print its related id component value.
echo "${RESPONSE_TEMPLATES}" | jq -r 'select(.templateId=="test").id'
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