我的JSON数据是:
{
"content":"{\"type\":3,\"from\":\"home\"}",
"id":"239",
"idtype":"0",
"timestamp":"1547957367281",
"type":"0"
}我想将其放入以下格式的表json_data中:
+-------------+
| from |
+-------------+
| home |
+-------------+我如何在这里使用分解函数来获得所需的输出?
发布于 2019-01-21 23:46:24
您可以使用regexp_replace删除\,也可以删除{之前和}之后的"。使用get_json_object或json_tuple提取属性。在您的数据示例上进行测试:
select get_json_object(json,'$.content.from') as `from`
from
(
select
regexp_replace(
regexp_replace(
regexp_replace(
'{"content":"{\"type\":3,\"from\":\"home\"}",
"id":"239",
"idtype":"0",
"timestamp":"1547957367281",
"type":"0"
}' --original data
,'\\\"','\"') --replace \" with "
,'\\"\\{','{') --remove " before {
,'\\}\\"','\\}') --remove " after } --these last two can be combined
as json
)s
;输出:
OK
from
home
Time taken: 0.329 seconds, Fetched: 1 row(s)最好逐个检查这些regexp_replaces,以确保它像预期的那样工作。希望你明白我的意思
https://stackoverflow.com/questions/54289524
复制相似问题