[英]How to extract all the keys in a JSON with BigQuery
I have a json data in Bigquery like this:我在 Bigquery 中有一个 json 数据,如下所示:
**document_id time_in_pending_per_user**
1 {"quqtC1DfyAk0d5bMi7GIE7":1735,"XmrBJS4hnqLLyDH1W5X7z2":6150,"system":0}
and I want to transform this data like this to parse:我想像这样转换这些数据来解析:
**user ID time_in_pending_per_user** document_id
quqtC1DfyAk0d5bMi7GIE7 1735 1
XmrBJS4hnqLLyDH1W5X7z2 6150 1
system 0 1
Can you help me?你能帮助我吗? thanks!
谢谢!
Consider below考虑以下
create temp function extract_keys(input string) returns array<string> language js as """
return Object.keys(JSON.parse(input));
""";
create temp function extract_values(input string) returns array<string> language js as """
return Object.values(JSON.parse(input));
""";
select user_id, val as time_in_pending_per_user, document_id
from your_table,
unnest(extract_keys(time_in_pending_per_user)) user_id with offset
join unnest(extract_values(time_in_pending_per_user)) val with offset
using(offset)
if applied to sample data in your question - output is如果应用于您问题中的示例数据 - output 是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.