无法在 Unix shell 中使用 JQ 迭代 JSON 响应对象

Not able to Iterate through JSON response object with JQ in Unix shell

我正在尝试遍历 UNIX 中的 JSON 对象,其想法是获取不同的值并将其附加到字符串并将其作为系统日志转发。下面是代码。

//picking up the length of Object
count=$(jq '.content | length' red)
#echo $count

    enter code here

for((i=0;i<$count;i++))
do
        echo "MY VALUE OF I"
        echo $i
        //THE BELOW LINE GIVES ERROR UPON USAGE of $i
        id="$(cat red | jq '.content[$i].id')"
        source=$(cat red | jq '.content[$i].entitySummary.source')
        .
        .

        #syslogString="ID=$id SOURCE=$source SUMMARY=$summaryText TITLE=$title DESCRIPTION=$description SEVERITY=$severity MITIGATION=$mitigation IMPACT=$impactDescrip$

        echo $id
        echo "value of ID ($id)"

我收到内容 [$i] 的编译错误并且无法获得相同的解决方法。

响应 class 如下所示:

Page {
    content ( array[ ClientIncident ] )
        The list of results that make up the page. The number of elements should be less than or equal to the currentPage size.
    currentPage ( Pagination )
        Size and offset information about the current page.
    total ( integer )
        The total number of results found. If there are a large number of results, this may be an estimate. Accuracy should improve as the page approaches the end of the resultset.
} 

在内容下,JSON 响应如下所示:

{
  "content": [
    {
      "id": 951653,
      "version": 12,
      "score": 100,
      "entitySummary": {
        "source": "somewebsite",
        "summaryText": "someTEXT here",
        "domain": "www.domian.com",
        "sourceDate": "2014-12-19T17:00:00.000Z",
        "type": "WEB_PAGE"
      },
      "type": "SomeTYPE",
      "title": "some Title",
      "description": "some description ",
      "occurred": "2014-12-19T17:00:00.000Z",
      "verified": "2014-12-19T17:17:22.326Z",
      "tags": [
        {
          "id": 424,
          "name": "Data Breach or Compromise",
          "type": "IMPACT_EFFECTS"
        },
        {
          "id": 1064,
          "name": "United States",
          "type": "TARGET_GEOGRAPHY"
        },
       ],
      "severity": "MEDIUM",
      "clientId": "NET",
      "alerted": "2014-12-19T17:39:55.500Z",
      "mitigation": "MititgationINFO",
      "impactDescription": "IMpact description": 0
    },
    {
      "id": 951174,
      "version": 8,
      "score": 100,
      "entitySummary": {

好的,我得到了答案。

我们可以使用下面的语法使 is 在 for 循环中工作。

id=$(cat red | jq '.content['${i}'].id')