繁体   English   中英

如何在雪花中解析这个 JSON 文件?

[英]How to parse this JSON file in Snowflake?

因此,我在存储 JSON 数据的 Snowflake 表中有一个列,但该列是 varchar 数据类型。

JSON 看起来像这样:

{   
    "FLAGS": [],   
    "BANNERS": {},   
    "TOOLS": {     
            "game.appConfig": {       
              "type": [         
                "small",       
                 "normal",        
                  "huge"
              ],      
              "flow": [         
                "control",       
                "noncontrol"
            ]   
        }  
    },   
    "PLATFORM": {} 
}

我只想过滤 TOOLS 中的数据,并希望得到以下结果:

TOOLS_ID 工具
游戏.appConfig 类型
游戏.appConfig 流动

我怎样才能做到这一点?

我假设 TOOL 可以有多个工具 ID,因此我编写了以下查询:

with mydata as ( select
'{
    "FLAGS": [],   
    "BANNERS": {},   
    "TOOLS": {     
            "game.appConfig": {       
              "type": [         
                "small",       
                 "normal",        
                  "huge"
              ],      
              "flow": [         
                "control",       
                "noncontrol"
            ]   
        }  
    },   
    "PLATFORM": {} 
}' as v1 )
select main.KEY TOOLS_ID, sub.KEY TOOLS
from mydata,
lateral flatten ( parse_json(v1):"TOOLS" ) main,
lateral flatten ( main.VALUE ) sub;

+----------------+-------+
|    TOOLS_ID    | TOOLS |
+----------------+-------+
| game.appConfig | flow  |
| game.appConfig | type  |
+----------------+-------+

假设列名是 C1,表名是 T1:

select a.t:"TOOLS":"game.appConfig"::string from (select 
parse_json(to_variant(C1))t from T1) a

暂无
暂无

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

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