json - 如何使用 sqlite json-extract 提取嵌套的 json
问题描述
如何使用 sqlite json-extract 或其他 sqlite json 命令提取嵌套的 json?
在这里我想提取given_id
"invoices": [{
........
"items": [{
"given_id": "TBC0003B",
...
}
]
}
]
谢谢。
解决方案
在 SQLite 中,您可以json_extract()
按如下方式使用:
select json_extract(my_json_col, '$.invoices[0].items[0].given_id') my_given_id from mytable
这为您提供了数组第一个元素下数组第一个元素的given_id
属性。items
invoices
with mytable as (select '{
"invoices": [{
"items": [{ "given_id": "TBC0003B" }]
}]
}' my_json_col)
select json_extract(my_json_col, '$.invoices[0].items[0].given_id') my_given_id from mytable
| my_given_id | | :------------ | | TBC0003B |
推荐阅读
- sql - 在 Spring Boot 中使用本机 SQL 查询仅选择所需的列
- datetime - Angular 5 中的日期时间范围选择器
- php - NotFoundHttpException 用于具有长文件名的图像
- c# - 未捕获的类型错误:无法读取未定义的属性“enqueueSetState”
- php - 具有文件类型创建的 symfony 4 表单集合实体
- hybris - B2B 混合模块生成不起作用
- java - 写入txt文件时按升序排序
- arrays - 为新系列增加价值
- java - Hibernate.update 是否需要重试?
- excel - 重命名 Subs 以供多次使用、移动行和 VBA