json - How do I parse JSON key pair values in BigQuery?
问题描述
I have a JSON that looks like this
"promo_codes": {
"AKNC": "",
"AZQE": "",
"BBVY": "xbKn2vA8Z2XoDSxawDIzFrzqSEf1",
"BJCR": "ou9Y3zXzGXU5loe2CjMGEDwCUln2"
}
In Bigquery, I would like to store these in a table with type REPEATED where you would have for instance promo_codes.key and promo_codes.value fields.
The resulting table should be one single row containing the list of codes (this JSON is for a single row, there are many others which need to be parsed with different codes).
How do I acomplish this?
Below is almost what I want, but it doesn't pair the correct user to the code.
ARRAY(
SELECT AS STRUCT
REGEXP_EXTRACT_ALL(JSON_EXTRACT(C.data, '$.promo_codes'), r'"([a-zA-Z0-9\.]+)":') as code,
REGEXP_EXTRACT_ALL(JSON_EXTRACT(C.data, '$.promo_codes'), r':"([a-zA-Z0-9\.]+)"') as user_id
) as promo_codes ,
解决方案
推荐阅读
- c# - 第一次使用 foreach 循环,但似乎无法做到这一点,即使它在网上到处都说代码是正确的
- c# - Xamarin Forms App Linking 使用参数
- python - 我需要为 HORZRES、VERTRES、LOGPIXELSX、LOGPIXELSY 等提供什么值才能打印固定尺寸的照片?
- amazon-web-services - 是否可以将 CloudWatch 警报设置为 3 或 4 分钟?
- enterprise-architect - 我可以在数据库图表中显示列的自定义标签吗?
- javascript - 根据 CSS 伪类获取内容
- python - Python:使用变换矩阵变换 STL-Mesh
- android - 从本地服务器推送通知
- python - 大于零的整数的 Python 输入验证
- node.js - npm:即使在 package.json 文件中定义了启动,也缺少启动脚本