用于从json检索分数的regex

p1iqtdky  于 2021-06-24  发布在  Hive
关注(0)|答案(2)|浏览(395)

我需要提取分数后的浮点数。

{"reason_desc":
   {
    "score":"0.1",
    "numOfIndicatrix":"0",
    "indicatrix":[]},
    "success":true,
    "id":"1555039965661065S427A2DCF5787920"
}

我希望输出为0.1或任何用“”括起来的数字。

hxzsmxv2

hxzsmxv21#

这个正则表达式可以帮助你 0.1 . 它将目标线分为两组,其中第二组( $2 )返回所需的浮点数:

("score":")([0-9\.\,]+)

6jygbczu

6jygbczu2#

您不需要在配置单元中使用regexp解析json,它具有相同的嵌入式函数:

with your_table as (--use your table instead of this
select '{"reason_desc":
   {
    "score":"0.1",
    "numOfIndicatrix":"0",
    "indicatrix":[]},
    "success":true,
    "id":"1555039965661065S427A2DCF5787920"
}' as json_col
)

select get_json_object(t.json_col,'$.reason_desc.score') as score
  from your_table t

结果:

0.1

另请参见:json\u tuple

相关问题