json - JMESPath Query exression
问题描述
I have a lists of Countries, States and Cities in below format.
[
{
"id": 1,
"name": "Afghanistan",
"states": [
{
"id": 3901,
"name": "Badakhshan",
"state_code": "BDS",
"latitude": "36.73477250",
"longitude": "70.81199530",
"cities": [
{
"id": 52,
"name": "Ashkāsham",
"latitude": "36.68333000",
"longitude": "71.53333000"
},
....
]
},
....
]
},
....
]
I have formatted using JMESPath as:
[*].{id: id, name: name, states: states[*].[name, cities]}
The output is:
[
{
"id": 1,
"name": "Afghanistan",
"states": [
[
"Badakhshan",
[
"Ashkāsham",
....
]
],
.....
]
},
...
]
What will be the correct query to get the output below?
[
{
"id": 1,
"name": "Afghanistan",
"states": [
[
"Badakhshan": [
"Ashkāsham",
....
]
],
...
]
},
....
]
If there's any other solution or better format, it would be very much appreciated.
解决方案
推荐阅读
- python - 当 html 表单允许文件上传时,Django 以“生成器引发的 StopIteration”停止
- android - 尝试共享偏好但出现错误
- apache-spark - Spark DataFrame / Dataset groupBy 通过 bucketBy 优化
- c - c mpi(生成分散聚集)用于可变数量的进程
- spring-data-r2dbc - 设置 r2dbcCustomConversions 时出现“无法找到类型 X 的 PersistentEntity”
- php - 如何在 postgresql 查询中转换 mysql 查询(group_concat)
- android - 实施 material.io 时出错 - 为什么会这样?
- excel - 如何使用多个数据源更新多个数据透视表?
- hash - 如何使用实现 sha2 板条箱中的 Digest 特征的类型(例如 Sha256)对结构进行哈希处理?
- oracle - 在一列中执行PL SQL条件并获取返回值