[
{
"path": "test",
"resources": [
{
"name": "testfile"
}
]
},
{
"path": "test-1",
"resources": [
{
"name": "testfile-1"
}
]
}
]
给定一个类似于上面的json,是否可以使用jsonPath以以下格式读取它?
[
{
"path": "test",
"name": "testfile"
},
{
"path": "test-1",
"name": "testfile-1"
}
]
可以放心地假设资源数组大小始终为1。
我尝试了$.[*]['path', ['resources'][0]['name']]
,但它没有显示路径的值。
发布于 2020-10-22 02:20:11
正如前面提到的,这不能用JSONPath完成;从不同级别选择项并将它们重新组合成新的数组元素是行不通的,您需要一个像Jolt这样的JSON转换器。
有不同的方法,但您可以使用如下所示的shift
转换器来获得所需的输出:
[
{
"operation": "shift",
"spec": {
"*": {
// Grab the value of clientName, and write it to
// bookMap. whatever is at clientId
"@path": "[&].path",
"@resources[0].name": "[&].name"
}
}
}
]
使用您自己的输入here在线试用它。
https://stackoverflow.com/questions/64372483
复制