在mysql5.8中用json_extract函数解析json

背景:某个字段的数据中是JSON,需要提取其中的卡号部分,如:

{"objType":"WARE","orderId":6771254073665082371,"values":["D3252","",""]}

需要提取其中的:D3252

 

示例如下:

select json_extract(x,'$.values[0]') 卡号
from
(
select '{"objType":"WARE","orderId":6771254073665082371,"values":["M2352","",""]}' x
union all
select '{"objType":"WARE","orderId":6771254073665082371,"values":["W3423","",""]}' x
union all
select '{"objType":"WARE","orderId":6771254073665082371,"values":["D3252","",""]}' x
) t

 返回:

卡号
"M2352"
"W3423"
"D3252"

 

参考:https://blog.csdn.net/lkforce/article/details/102940249

 

posted @ 2021-12-01 09:24  xiaoyongdata  阅读(257)  评论(0编辑  收藏  举报