简体   繁体   English

JSON 大查询中的提取物

[英]JSON EXTRACT IN BIG QUERY

I Currently have a column in json format with multiple items.我目前有一个 json 格式的列,其中包含多个项目。 The struct is like the following:结构如下:

phones": [{"phone": "11111111", "type": "CELLPHONE"}, {"phone": "222222222", "type":"CELLPHONE"}, {"phone": "99999999", "type": "CELLPHONE"}]电话”:[{“电话”:“11111111”,“类型”:“手机”},{“电话”:“222222222”,“类型”:“手机”},{“电话”:“99999999”,“类型”:“手机”}]

I tried: json_extract(Contacts,'$.phones.phone') as phone_number but it only extracts the first one.我试过: json_extract(Contacts,'$.phones.phone') as phone_number但它只提取第一个。

JSON_EXTRACT_ARRAY(Contacts,'$.phones') as phone_contacts gives me an array, But Im getting error trying to unnest it. JSON_EXTRACT_ARRAY(Contacts,'$.phones') as phone_contacts给了我一个数组,但我在尝试解除嵌套时出错。

Does anybody know any approach to solve this problems?有人知道解决这个问题的任何方法吗?

Thanks in Advance.提前致谢。

Consider below考虑下面

select json_value(phone_contact, '$.phone') phone,
  json_value(phone_contact, '$.type') type
from your_table, 
unnest(json_extract_array(Contacts,'$.phones')) phone_contact    

if applied to sample data in your question - output is如果应用于您问题中的示例数据 - output 是

在此处输入图像描述

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

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