如何编写SQL查询以从JSON中获取数据(图像

llycmphe  于 2023-02-10  发布在  其他
关注(0)|答案(1)|浏览(126)

Json对象

{"images": ["https://bijnis.s3.ap-south-1.amazonaws.com/2487dc60-c3b5-4cf9-a3a2-34f73683ac5a.jpg"], 
"remarks": "done", 
"documentList": [{"id": "GST", "value": "GST"}]}, GST, https://bijnis.s3.ap-south-1.amazonaws.com/2487dc60-c3b5-4cf9-a3a2-34f73683ac5a.jpg
select
    json_extract(my_json_field, '$.images'),
    json_extract(my_json_field, '$.remarks'),
    json_extract(my_json_field, '$.documentList.id'),
    json_extract(my_json_field, '$.documentList.value')
from Jason Object;
3pmvbmvn

3pmvbmvn1#

按如下方式使用JSON_VALUE

WITH cte as (
select '{"images": ["https://bijnis.s3.ap-south-1.amazonaws.com/2487dc60-c3b5-4cf9-a3a2-34f73683ac5a.jpg"], 
"remarks": "done", 
"documentList": [{"id": "GST", "value": "GST"}]}' as json
)
select JSON_VALUE(json, '$.images') AS images,
    JSON_VALUE(json, '$.remarks') AS remarks,
    JSON_VALUE(json, '$.documentList[0].id') AS id,
    JSON_VALUE(json, '$.documentList[0].value') AS value
from cte;

相关问题