Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Unix shell中使用JQ迭代JSON响应对象_Json_Loops_Unix_Jq - Fatal编程技术网

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

无法在Unix shell中使用JQ迭代JSON响应对象,json,loops,unix,jq,Json,Loops,Unix,Jq,我试图在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 //TH

我试图在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)"
在内容下,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')

json内容看起来像什么?如果没有这些信息,我们将无法帮助您。感谢您的回复Jeff,我现在已经添加了JSON响应。
id=$(cat red | jq '.content['${i}'].id')