1

我创建了一个函数,它使用 Google Video Intelligence API 输出下面的 json。我正在尝试将 json 转换为换行符分隔格式,以便可以将 json 文件上传到 Big Query。

我尝试了以下 JQ 代码,但它不会将其转换为 BiG Query 接受的格式。

非常感谢任何帮助。

$ 猫 a.json | jq -c '.[]'

来自视频智能的完整 json 输出

{
  "annotation_results": [ {
    "input_uri": "/mastersproject-252719.appspot.com/AEnB2UoTKtyPJd1X88yUBKC60dn3kp6qrnnE91Q5PylS9RqotQWrt2TzFPE7kG1UHtxoBYyWX5mo7zoXU1jzwnNe_WRD-t0QeFSoHU4g-WJZTfeQV4cpFNY.4-FicKZIT3vtFBd2",
    "segment": {
      "start_time_offset": {

      },
      "end_time_offset": {
        "seconds": 126,
        "nanos": 160000000
      }
    },
    "shot_annotations": [ {
      "start_time_offset": {

      },
      "end_time_offset": {
        "seconds": 3,
        "nanos": 960000000
      }
    }, {
      "start_time_offset": {
        "seconds": 4
      },
      "end_time_offset": {
        "seconds": 5,
        "nanos": 840000000
      }
    }, {
      "start_time_offset": {
        "seconds": 5,
        "nanos": 880000000
      },
      "end_time_offset": {
        "seconds": 11,
        "nanos": 40000000
      }
    }, {
      "start_time_offset": {
        "seconds": 11,
        "nanos": 80000000
      },
      "end_time_offset": {
        "seconds": 14,
        "nanos": 640000000
      }
    }, {
      "start_time_offset": {
        "seconds": 14,
        "nanos": 680000000
      },
      "end_time_offset": {
        "seconds": 15,
        "nanos": 400000000
      }
    }, {
      "start_time_offset": {
        "seconds": 15,
        "nanos": 440000000
      },
      "end_time_offset": {
        "seconds": 19,
        "nanos": 840000000
      }
    }, {
      "start_time_offset": {
        "seconds": 19,
        "nanos": 880000000
      },
      "end_time_offset": {
        "seconds": 21,
        "nanos": 880000000
      }
    }, {
      "start_time_offset": {
        "seconds": 21,
        "nanos": 920000000
      },
      "end_time_offset": {
        "seconds": 25,
        "nanos": 120000000
      }
    }, {
      "start_time_offset": {
        "seconds": 25,
        "nanos": 160000000
      },
      "end_time_offset": {
        "seconds": 30,
        "nanos": 880000000
      }
    }, {
      "start_time_offset": {
        "seconds": 30,
        "nanos": 920000000
      },
      "end_time_offset": {
        "seconds": 32,
        "nanos": 960000000
      }
    }, {
      "start_time_offset": {
        "seconds": 33
      },
      "end_time_offset": {
        "seconds": 38,
        "nanos": 80000000
      }
    }, {
      "start_time_offset": {
        "seconds": 38,
        "nanos": 120000000
      },
      "end_time_offset": {
        "seconds": 44,
        "nanos": 80000000
      }
    }, {
      "start_time_offset": {
        "seconds": 44,
        "nanos": 120000000
      },
      "end_time_offset": {
        "seconds": 47,
        "nanos": 680000000
      }
    }, {
      "start_time_offset": {
        "seconds": 47,
        "nanos": 720000000
      },
      "end_time_offset": {
        "seconds": 51,
        "nanos": 120000000
      }
    }, {
      "start_time_offset": {
        "seconds": 51,
        "nanos": 160000000
      },
      "end_time_offset": {
        "seconds": 56,
        "nanos": 640000000
      }
    }, {
      "start_time_offset": {
        "seconds": 56,
        "nanos": 680000000
      },
      "end_time_offset": {
        "seconds": 59,
        "nanos": 40000000
      }
    }, {
      "start_time_offset": {
        "seconds": 59,
        "nanos": 80000000
      },
      "end_time_offset": {
        "seconds": 62,
        "nanos": 880000000
      }
    }, {
      "start_time_offset": {
        "seconds": 62,
        "nanos": 920000000
      },
      "end_time_offset": {
        "seconds": 70,
        "nanos": 640000000
      }
    }, {
      "start_time_offset": {
        "seconds": 70,
        "nanos": 680000000
      },
      "end_time_offset": {
        "seconds": 74,
        "nanos": 240000000
      }
    }, {
      "start_time_offset": {
        "seconds": 74,
        "nanos": 280000000
      },
      "end_time_offset": {
        "seconds": 76,
        "nanos": 40000000
      }
    }, {
      "start_time_offset": {
        "seconds": 76,
        "nanos": 80000000
      },
      "end_time_offset": {
        "seconds": 82,
        "nanos": 240000000
      }
    }, {
      "start_time_offset": {
        "seconds": 82,
        "nanos": 280000000
      },
      "end_time_offset": {
        "seconds": 86
      }
    }, {
      "start_time_offset": {
        "seconds": 86,
        "nanos": 40000000
      },
      "end_time_offset": {
        "seconds": 89,
        "nanos": 720000000
      }
    }, {
      "start_time_offset": {
        "seconds": 89,
        "nanos": 760000000
      },
      "end_time_offset": {
        "seconds": 99,
        "nanos": 680000000
      }
    }, {
      "start_time_offset": {
        "seconds": 99,
        "nanos": 720000000
      },
      "end_time_offset": {
        "seconds": 104,
        "nanos": 360000000
      }
    }, {
      "start_time_offset": {
        "seconds": 104,
        "nanos": 400000000
      },
      "end_time_offset": {
        "seconds": 107,
        "nanos": 440000000
      }
    }, {
      "start_time_offset": {
        "seconds": 107,
        "nanos": 480000000
      },
      "end_time_offset": {
        "seconds": 108,
        "nanos": 640000000
      }
    }, {
      "start_time_offset": {
        "seconds": 108,
        "nanos": 680000000
      },
      "end_time_offset": {
        "seconds": 112,
        "nanos": 160000000
      }
    }, {
      "start_time_offset": {
        "seconds": 112,
        "nanos": 200000000
      },
      "end_time_offset": {
        "seconds": 114,
        "nanos": 640000000
      }
    }, {
      "start_time_offset": {
        "seconds": 114,
        "nanos": 680000000
      },
      "end_time_offset": {
        "seconds": 117,
        "nanos": 520000000
      }
    }, {
      "start_time_offset": {
        "seconds": 117,
        "nanos": 560000000
      },
      "end_time_offset": {
        "seconds": 118,
        "nanos": 760000000
      }
    }, {
      "start_time_offset": {
        "seconds": 118,
        "nanos": 800000000
      },
      "end_time_offset": {
        "seconds": 121,
        "nanos": 80000000
      }
    }, {
      "start_time_offset": {
        "seconds": 121,
        "nanos": 120000000
      },
      "end_time_offset": {
        "seconds": 122,
        "nanos": 320000000
      }
    }, {
      "start_time_offset": {
        "seconds": 122,
        "nanos": 360000000
      },
      "end_time_offset": {
        "seconds": 124,
        "nanos": 200000000
      }
    }, {
      "start_time_offset": {
        "seconds": 124,
        "nanos": 240000000
      },
      "end_time_offset": {
        "seconds": 126,
        "nanos": 160000000
      }
    } ]
  } ]
}

4

1 回答 1

0

我看到您在堆栈溢出帖子中尝试了建议的 JQ 命令。您需要使用适合您情况的不同 JQ 命令。

我个人试过:

cat <filename>.json | jq -c '.'

它有效。意思是,最终结果是一个有效的换行符分隔的 json。

但是,根据您的最终表模式,它可能需要更多调整。

如果它不起作用,请在描述中包含您的最终表模式,以便我们更好地理解目标是什么。

于 2020-06-01T09:30:23.157 回答