presto解析json串中的布尔值
json串为:
{
"status":"SUCCESS",
"bank_account_number":"8***22",
"bank_code":"BCA",
"updated":"2021-06-29T07:41:09.388Z",
"is_normal_account":true,
"name_matching_result":"MATCH",
"id":"60dace954b96181226cfbac7"
}
目标是需要把其中的is_normal_account中的值提取出来,presto中以往拆json串用的都是json_extract,但由于这个是boolean,所以会报错。
解决方法有2个:
1.用json_extract_scalar来进行解析:
select json_extract_scalar(res_message,'$.is_normal_account') as is_normal_account
2.继续用json_extract,但把取出来的值进行转化:
(1)转成tinyint:
select cast(json_extract(res_message,'$.is_normal_account') as tinyint)
(2)转成boolean:
select cast(json_extract(res_message,'$.is_normal_account') as boolean)