Home > Enterprise >  command not found when executing jq for manipulating variable
command not found when executing jq for manipulating variable

Time:09-20

What I do:

  1. RESPONSE_TEMPLATES=$(curl "https://maydomain.com/test)
  2. I get back JSON which looks like this:
    {
      "templateId": "test",
      "id": 1621030
    }
    {
      "templateId": "test1",
      "id": 5014
    }
    {
      "templateId": "test3",
      "id": 5015
    }
  1. 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.

CodePudding user response:

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'
  • Related