json - 尝试从bigquery上的一到多列中提取json值

标签 json google-bigquery text-extraction

我正在尝试对其中一列包含以下内容的表进行建模:

[{"code": "SEEYOUSOON100", "amount": "250.00", "type": "percentage"}]

来自 [bigquery documentation] 的任何解决方案网站返回 null。

最佳答案

考虑以下方法

select 
  json_extract_scalar(json, '$.code') as code,
  json_extract_scalar(json, '$.amount') as amount,
  json_extract_scalar(json, '$.type') as type
from your_table, 
unnest(json_extract_array(col)) json       

如果应用于问题中的示例数据 - 输出为

enter image description here

您可以使用下面的 cte 来播放/测试上面的内容

with your_table as (
  select '[{"code": "SEEYOUSOON100", "amount": "250.00", "type": "percentage"}]' col
)
select 
  json_extract_scalar(json, '$.code') as code,
  json_extract_scalar(json, '$.amount') as amount,
  json_extract_scalar(json, '$.type') as type
from your_table, 
unnest(json_extract_array(col)) json

关于json - 尝试从bigquery上的一到多列中提取json值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70758809/

相关文章:

android - 恢复数据放入 JSONObject 的顺序

sql - 如何对每个唯一版本: For each unique id,,抓取最好的分数整理成表格

mysql - 根据Google大查询的错误消息日志查找缺陷线

python - 我应该如何提取 % 分隔标签

java - 如何使用 Spring RestTemplate 将 JSON 作为参数发送到 url 中?

javascript - Jquery - 计算 JSON 对象

pdf - 带有坐标的PDF文本提取

machine-learning - 从文本中提取关键词/关键短语

json - 使用未声明的类型 'JSON' 和使用未解析的标识符 'JSONEncoding'

google-bigquery - Google Big Query 在类型为 ARRAY 的值上提供无法访问字段页面