gpt4 book ai didi

json - 在HIVE中解析此JSON

转载 作者:行者123 更新时间:2023-12-02 21:12:33 25 4
gpt4 key购买 nike

我对JSON完全陌生。我在HIVE列之一中的JSON下面。我不确定如何安排{}和[],但是尽了最大的努力。

{
"main_key":
[
{
"type":"RESPONSIBLE",
"lastName":"John"
},
{
"ids":
[
{
"id":"001815015",
"qual":"PIN"
},
{
"id":"592852900",
"qual":"TIN"
}
],
"type":"BILLING",
"lastName":"Joe"
},
{
"ids":
[
{
"id":"002329056",
"qual":"PIN"
}
],
"type":"SVC",
"lastName":"Jame"
}
]
}

上面的JSON应该解析如下。需要Hive查询可以做到这一点。

enter image description here
谢谢,

最佳答案

您可以使用get_json_objectjson_tuple
示例:src_json表是单列(json),单行表:

+----+
                               json
+----+
{"store":
  {"fruit":\[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],
   "bicycle":{"price":19.95,"color":"red"}
  },
 "email":"amy@only_for_json_udf_test.net",
 "owner":"amy"
}
+----+



hive> SELECT get_json_object(src_json.json, '$.owner') as owner FROM src_json;
amy
 
hive> SELECT get_json_object(src_json.json, '$.store.fruit\[0]') as fruitdata FROM src_json;
{"weight":8,"type":"apple"}
 
hive> SELECT get_json_object(src_json.json, '$.non_exist_key') FROM src_json;
NULL

more info

关于json - 在HIVE中解析此JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39917720/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com