Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
从命令行使用jq和curl解析JSON数据_Json_Command Line_Jq - Fatal编程技术网

从命令行使用jq和curl解析JSON数据

从命令行使用jq和curl解析JSON数据,json,command-line,jq,Json,Command Line,Jq,我想从命令行使用jq和curl解析JSON数据,但我没有成功。事实上,我想得到response>textAnnotations>description的值,但我做错了什么。这是我的命令: curl -X POST > response.txt \ -H "Content-Type: application/json; charset=utf-8" \ --data "{ 'requests': [ { 'image': {

我想从命令行使用jq和curl解析JSON数据,但我没有成功。事实上,我想得到response>textAnnotations>description的值,但我做错了什么。这是我的命令:

curl -X POST > response.txt \
     -H "Content-Type: application/json; charset=utf-8" \
     --data "{
      'requests': [
        {
          'image': {
            'source': {
              'imageUri': 'http://adn-cdn2.avadeo.net/articles/vignettes/grandes/146.jpg'
            }
          },
          'features': [
            {
              'type': 'TEXT_DETECTION'
            }
          ]
        }
      ]
    }" "https://vision.googleapis.com/v1/images:annotate?key=XXXXXXXXXXXXXXXXXXX" | jq -r '.responses.textAnnotations.description'
如果我不使用JQ过滤,这里是旋度的答案:

    {
  "responses": [
    {
      "textAnnotations": [
        {
          "locale": "und",
          "description": "24\nmois\n12\nmois\n",
          "boundingPoly": {
            "vertices": [
              {
                "x": 12,
                "y": 24
              },
              {
                "x": 285,
                "y": 24
              },
              {
                "x": 285,
                "y": 206
              },
              {
                "x": 12,
                "y": 206
              }
            ]
          }
        },
        {
          "description": "24",
          "boundingPoly": {
            "vertices": [
              {
                "x": 216,
                "y": 24
              },
              {
                "x": 285,
                "y": 24
              },
              {
                "x": 285,
                "y": 83
              },
              {
                "x": 216,
                "y": 83
              }
            ]
          }
        },
        {
          "description": "mois",
          "boundingPoly": {
            "vertices": [
              {
                "x": 223,
                "y": 83
              },
              {
                "x": 280,
                "y": 84
              },
              {
                "x": 280,
                "y": 110
              },
              {
                "x": 223,
                "y": 109
              }
            ]
          }
        },
        {
          "description": "12",
          "boundingPoly": {
            "vertices": [
              {
                "x": 12,
                "y": 122
              },
              {
                "x": 81,
                "y": 122
              },
              {
                "x": 81,
                "y": 179
              },
              {
                "x": 12,
                "y": 179
              }
            ]
          }
        },
        {
          "description": "mois",
          "boundingPoly": {
            "vertices": [
              {
                "x": 19,
                "y": 177
              },
              {
                "x": 76,
                "y": 176
              },
              {
                "x": 76,
                "y": 205
              },
              {
                "x": 19,
                "y": 206
              }
            ]
          }
        }
      ],
      "fullTextAnnotation": {
        "pages": [
          {
            "width": 300,
            "height": 225,
            "blocks": [
              {
                "boundingBox": {
                  "vertices": [
                    {
                      "x": 216,
                      "y": 24
                    },
                    {
                      "x": 285,
                      "y": 24
                    },
                    {
                      "x": 285,
                      "y": 83
                    },
                    {
                      "x": 216,
                      "y": 83
                    }
                  ]
                },
                "paragraphs": [
                  {
                    "boundingBox": {
                      "vertices": [
                        {
                          "x": 216,
                          "y": 24
                        },
                        {
                          "x": 285,
                          "y": 24
                        },
                        {
                          "x": 285,
                          "y": 83
                        },
                        {
                          "x": 216,
                          "y": 83
                        }
                      ]
                    },
                    "words": [
                      {
                        "boundingBox": {
                          "vertices": [
                            {
                              "x": 216,
                              "y": 24
                            },
                            {
                              "x": 285,
                              "y": 24
                            },
                            {
                              "x": 285,
                              "y": 83
                            },
                            {
                              "x": 216,
                              "y": 83
                            }
                          ]
                        },
                        "symbols": [
                          {
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 216,
                                  "y": 25
                                },
                                {
                                  "x": 248,
                                  "y": 25
                                },
                                {
                                  "x": 248,
                                  "y": 76
                                },
                                {
                                  "x": 216,
                                  "y": 76
                                }
                              ]
                            },
                            "text": "2"
                          },
                          {
                            "property": {
                              "detectedBreak": {
                                "type": "EOL_SURE_SPACE"
                              }
                            },
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 255,
                                  "y": 24
                                },
                                {
                                  "x": 285,
                                  "y": 24
                                },
                                {
                                  "x": 285,
                                  "y": 83
                                },
                                {
                                  "x": 255,
                                  "y": 83
                                }
                              ]
                            },
                            "text": "4"
                          }
                        ]
                      }
                    ]
                  }
                ],
                "blockType": "TEXT"
              },
              {
                "boundingBox": {
                  "vertices": [
                    {
                      "x": 223,
                      "y": 83
                    },
                    {
                      "x": 280,
                      "y": 84
                    },
                    {
                      "x": 280,
                      "y": 110
                    },
                    {
                      "x": 223,
                      "y": 109
                    }
                  ]
                },
                "paragraphs": [
                  {
                    "boundingBox": {
                      "vertices": [
                        {
                          "x": 223,
                          "y": 83
                        },
                        {
                          "x": 280,
                          "y": 84
                        },
                        {
                          "x": 280,
                          "y": 110
                        },
                        {
                          "x": 223,
                          "y": 109
                        }
                      ]
                    },
                    "words": [
                      {
                        "boundingBox": {
                          "vertices": [
                            {
                              "x": 223,
                              "y": 83
                            },
                            {
                              "x": 280,
                              "y": 84
                            },
                            {
                              "x": 280,
                              "y": 110
                            },
                            {
                              "x": 223,
                              "y": 109
                            }
                          ]
                        },
                        "symbols": [
                          {
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 223,
                                  "y": 89
                                },
                                {
                                  "x": 242,
                                  "y": 89
                                },
                                {
                                  "x": 242,
                                  "y": 108
                                },
                                {
                                  "x": 223,
                                  "y": 108
                                }
                              ]
                            },
                            "text": "m"
                          },
                          {
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 246,
                                  "y": 88
                                },
                                {
                                  "x": 259,
                                  "y": 88
                                },
                                {
                                  "x": 259,
                                  "y": 108
                                },
                                {
                                  "x": 246,
                                  "y": 108
                                }
                              ]
                            },
                            "text": "o"
                          },
                          {
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 262,
                                  "y": 83
                                },
                                {
                                  "x": 264,
                                  "y": 83
                                },
                                {
                                  "x": 264,
                                  "y": 109
                                },
                                {
                                  "x": 262,
                                  "y": 109
                                }
                              ]
                            },
                            "text": "i"
                          },
                          {
                            "property": {
                              "detectedBreak": {
                                "type": "EOL_SURE_SPACE"
                              }
                            },
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 269,
                                  "y": 89
                                },
                                {
                                  "x": 280,
                                  "y": 89
                                },
                                {
                                  "x": 280,
                                  "y": 108
                                },
                                {
                                  "x": 269,
                                  "y": 108
                                }
                              ]
                            },
                            "text": "s"
                          }
                        ]
                      }
                    ]
                  }
                ],
                "blockType": "TEXT"
              },
              {
                "boundingBox": {
                  "vertices": [
                    {
                      "x": 12,
                      "y": 122
                    },
                    {
                      "x": 81,
                      "y": 122
                    },
                    {
                      "x": 82,
                      "y": 206
                    },
                    {
                      "x": 13,
                      "y": 206
                    }
                  ]
                },
                "paragraphs": [
                  {
                    "boundingBox": {
                      "vertices": [
                        {
                          "x": 12,
                          "y": 122
                        },
                        {
                          "x": 81,
                          "y": 122
                        },
                        {
                          "x": 82,
                          "y": 206
                        },
                        {
                          "x": 13,
                          "y": 206
                        }
                      ]
                    },
                    "words": [
                      {
                        "boundingBox": {
                          "vertices": [
                            {
                              "x": 12,
                              "y": 122
                            },
                            {
                              "x": 81,
                              "y": 122
                            },
                            {
                              "x": 81,
                              "y": 179
                            },
                            {
                              "x": 12,
                              "y": 179
                            }
                          ]
                        },
                        "symbols": [
                          {
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 12,
                                  "y": 122
                                },
                                {
                                  "x": 43,
                                  "y": 122
                                },
                                {
                                  "x": 43,
                                  "y": 175
                                },
                                {
                                  "x": 12,
                                  "y": 175
                                }
                              ]
                            },
                            "text": "1"
                          },
                          {
                            "property": {
                              "detectedBreak": {
                                "type": "EOL_SURE_SPACE"
                              }
                            },
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 50,
                                  "y": 122
                                },
                                {
                                  "x": 81,
                                  "y": 122
                                },
                                {
                                  "x": 81,
                                  "y": 179
                                },
                                {
                                  "x": 50,
                                  "y": 179
                                }
                              ]
                            },
                            "text": "2"
                          }
                        ]
                      },
                      {
                        "boundingBox": {
                          "vertices": [
                            {
                              "x": 19,
                              "y": 177
                            },
                            {
                              "x": 76,
                              "y": 176
                            },
                            {
                              "x": 76,
                              "y": 205
                            },
                            {
                              "x": 19,
                              "y": 206
                            }
                          ]
                        },
                        "symbols": [
                          {
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 19,
                                  "y": 186
                                },
                                {
                                  "x": 38,
                                  "y": 186
                                },
                                {
                                  "x": 38,
                                  "y": 205
                                },
                                {
                                  "x": 19,
                                  "y": 205
                                }
                              ]
                            },
                            "text": "m"
                          },
                          {
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 42,
                                  "y": 186
                                },
                                {
                                  "x": 55,
                                  "y": 186
                                },
                                {
                                  "x": 55,
                                  "y": 206
                                },
                                {
                                  "x": 42,
                                  "y": 206
                                }
                              ]
                            },
                            "text": "o"
                          },
                          {
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 58,
                                  "y": 177
                                },
                                {
                                  "x": 60,
                                  "y": 177
                                },
                                {
                                  "x": 60,
                                  "y": 205
                                },
                                {
                                  "x": 58,
                                  "y": 205
                                }
                              ]
                            },
                            "text": "i"
                          },
                          {
                            "property": {
                              "detectedBreak": {
                                "type": "EOL_SURE_SPACE"
                              }
                            },
                            "boundingBox": {
                              "vertices": [
                                {
                                  "x": 65,
                                  "y": 186
                                },
                                {
                                  "x": 76,
                                  "y": 186
                                },
                                {
                                  "x": 76,
                                  "y": 205
                                },
                                {
                                  "x": 65,
                                  "y": 205
                                }
                              ]
                            },
                            "text": "s"
                          }
                        ]
                      }
                    ]
                  }
                ],
                "blockType": "TEXT"
              }
            ]
          }
        ],
        "text": "24\nmois\n12\nmois\n"
      }
    }
  ]
}
你能帮帮我吗


谢谢大家:)

响应和文本注释都是数组,所以据我所知,您必须循环遍历它们,或者访问第一个响应元素的第一个文本注释,如:响应[0]。文本注释[0]。说明


如果可能的话,我建议循环。

如果您想要在.responses[]下的所有描述。text您可以编写注释:

.responses[].textAnnotations[].description 
它的缩写是:

.responses[] | .textAnnotations[] |.description 
这实际上是“for”循环中的“for”循环