在get_json_对象的搜索字符串中包含$
在get_json_对象的搜索字符串中包含$,json,hive,hiveql,Json,Hive,Hiveql,$用作get\u json\u对象的根对象。我的json字符串已经在json键的名称中包含了$,如何提取它的值?我不想使用json\u元组 create external table testing_hive (records string); insert into testing_hive values("{\"$num\":\"hey\"}"); select get_json_object(testing_hive.records, '$.$num') from testing_hiv
$
用作get\u json\u对象的根对象。我的json字符串已经在json键的名称中包含了$
,如何提取它的值?我不想使用json\u元组
create external table testing_hive (records string);
insert into testing_hive values("{\"$num\":\"hey\"}");
select get_json_object(testing_hive.records, '$.$num') from testing_hive;
您可以将“$num”
替换为不包含$
的其他内容,例如“xx_num”
:
结果:
hey
您还可以在单个regex_replace中用其他前缀替换所有键的$for:
regexp_replace(testing_hive.records,'\\"\\$(.*?\\":)','\\"xx_$1')
我在模式中包括了“:
,以确保它只匹配键,而不匹配值。如果要删除$
并保留键而不保留$
,请使用'$1'
,而不是'\\\\“xx\$1'
,作为替换
希望你有这个想法。相应地修改正则表达式模式 请问不使用json_元组的原因是什么?基本上json太嵌套了,希望避免每次都使用横向视图。但是,最终使用了json_元组
regexp_replace(testing_hive.records,'\\"\\$(.*?\\":)','\\"xx_$1')