【问题标题】:Turning JSON blob into BQ friendly format with JQ使用 JQ 将 JSON blob 转换为 BQ 友好格式
【发布时间】:2019-02-12 19:18:29
【问题描述】:

首先,我几乎没有使用 JSON、JQ 或 Java 方面的任何东西的经验。我花了很多时间尝试使用 jq 命令行函数来正确格式化测试数据块,以便我可以轻松地将其输入到 Google BigQuery 中。

{
    "total_items": 848,
    "page_count": 34,
    "items": [
        {
            "landing_id": "708d9e3eb106820f98162d879198774b",
            "token": "708d9e3eb106820f98162d879198774b",
            "response_id": "708d9e3eb106820f98162d879198774b",
            "landed_at": "2019-02-12T01:58:02Z",
            "submitted_at": "2019-02-12T01:58:31Z",
            "metadata": {
                "user_agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3560.98 Safari/537.36",
                "platform": "other",
                "referer": "https://test.typeform.com/to/LTYE9W?prefilled_answer=8&email=test.x20a@gmail.com",
                "network_id": "35b9eae170",
                "browser": "default"
            },
            "answers": [
                {
                    "field": {
                        "id": "fX64BkjuxYy1",
                        "type": "opinion_scale",
                        "ref": "97f8e18ad06a02e6"
                    },
                    "type": "number",
                    "number": 8
                },
                {
                    "field": {
                        "id": "lYeFxbL67g8B",
                        "type": "multiple_choice",
                        "ref": "78d09e15-7d42-49ec-9f9d-004bf7d3058a"
                    },
                    "type": "choices",
                    "choices": {
                        "labels": [
                            "Experience"
                        ]
                    }
                },
                {
                    "field": {
                        "id": "D3ubKSVfNnlY",
                        "type": "multiple_choice",
                        "ref": "684cb3bd-09cb-4f27-8e7d-baef6a09f787"
                    },
                    "type": "choices",
                    "choices": {
                        "labels": [
                            "Condition"
                        ]
                    }
                },
                {
                    "field": {
                        "id": "UccviSuUQPio",
                        "type": "yes_no",
                        "ref": "ed7e0d9c-5b62-4b0f-9395-54a53d125711"
                    },
                    "type": "boolean",
                    "boolean": false
                }
            ],
            "hidden": {
                "email": "test.x20a@gmail.com"
            }
        }
        ]
}

I've been using this tutorial, but with no success, and it's getting incredibly frustrating

假设我想要所有字段,但我想去掉包含total_itemspage_count 的顶部部分。所以本质上,一切都以landing_id 开头。我很抱歉没有进一步深入我之前为大家提供基线的尝试,但我只是没有得到任何结果。

【问题讨论】:

    标签: json google-bigquery jq


    【解决方案1】:

    对于给定的示例:

     jq -c  .items[] lala.json  > lala.jq.json
    

    然后您可以加载到 BigQuery:

     bq load --source_format NEWLINE_DELIMITED_JSON --autodetect fh-bigquery:deleting.testjson lala.jq.json
    

    然后就可以查询了:

    请注意,用户“peak”的答案缺少 -c[] 以控制输出并从数组中拆分为不同的项目。

    【讨论】:

    • 这个答案让人大跌眼镜!非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 2018-07-20
    • 1970-01-01
    • 2021-03-19
    • 2019-05-14
    • 1970-01-01
    • 2012-11-08
    相关资源
    最近更新 更多