简体   繁体   English

Big Query 中的 JSON 问题

[英]JSON issue in Big Query

I have scenario to parse the json data which is of one column in table.我有一个场景来解析表中一列的json数据。 Issue is that below Response column as json generated by Datastore backup to BigQuery.问题是下面的响应列作为由 Datastore 备份到 BigQuery 生成的 json。 It has '\\'attached to every data.它有 '\\' 附加到每个数据。

Reponse": "[
  {
    \"questionId\":5121566669012992,
    \"answereId\":0,
    \"answeredText\":\"Summer\"
  },{
    \"questionId\":5166851730440192,
    \"answereId\":0,
    \"answeredText\":\"Barcelona\"
  },{
    \"questionId\":6304057064947712,
    \"answereId\":0,
    \"answeredText\":\"Kitesurf\"
  }
]"

How do I parse the below to get value for questionId using BigQuery?如何使用 BigQuery 解析以下内容以获取 questionId 的值?

JSON_EXTRACT cannot return REPEATED field, it can only do one match - hence no support for * JSON_EXTRACT不能返回 REPEATED 字段,它只能进行一次匹配 - 因此不支持 *

you can get the first position using hardcoded indexes as您可以使用硬编码索引获得第一个位置

SELECT JSON_EXTRACT_SCALAR('[
  {
    \"questionId\":5121566669012992,
    \"answereId\":0,
    \"answeredText\":\"Summer\"
  },{
    \"questionId\":5166851730440192,
    \"answereId\":0,
    \"answeredText\":\"Barcelona\"
  },{
    \"questionId\":6304057064947712,
    \"answereId\":0,
    \"answeredText\":\"Kitesurf\"
  } 
]', '$[0].questionId') AS str;

This returns:这将返回:

+-----+------------------+---+
| Row |       str        |   |
+-----+------------------+---+
|   1 | 5121566669012992 |   |
+-----+------------------+---+

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM