在一个相当复杂的 JSON 对象中,我试图获取带有父值的键。
{
"provinces": [
{
"short": "ska",
"tiletype": "water",
"provinceOutlinePath": "M255.848,145.321l19.839,0.054l12.677,8.62l6.085,-8.62l-8.62,-29.41l-30.488,13.637l0.507,15.719Z",
"unionParts": [
{
"id": "main",
"unionPartPath": "M255.848,145.321l19.839,0.054l12.677,8.62l6.085,-8.62l-8.62,-29.41l-30.488,13.637l0.507,15.719Z"
},
{
"id": "main",
"unionPartPath": "M255.848,145.321l19.839,0.054l12.677,8.62l6.085,-8.62l-8.62,-29.41l-30.488,13.637l0.507,15.719Z"
}
]
},
{
"short": "nws",
"tiletype": "water",
"provinceOutlinePath": "M140.038,0.667l34.86,68.197l-6.338,27.888l12.677,3.169l70.988,-17.747l100.144,-62.115l1.268,-19.392l-213.599,0Z",
"unionParts": [
{
"id": "main",
"unionPartPath": "M140.038,0.667l34.86,68.197l-6.338,27.888l12.677,3.169l70.988,-17.747l100.144,-62.115l1.268,-19.392l-213.599,0Z"
}
]
}
]
}
我想将对象更改为:
[
{
"short": ska,
"unionPartPath": "<Path>"
},
{
"short": ska,
"unionPartPath": "<AnotherPath>"
},
{
"short": nws,
"unionPartPath": "<Path>"
}
]
我已经浏览了整个文档,但没有发现任何类似于 .parent()
方法的内容。
也许可以通过一些高阶函数来实现所需的结果,但目前我不知道如何实现这一点。
最佳答案
要在 JSONata 中执行此操作,您需要以下表达式
provinces.($short := short; unionParts.{
'short': $short,
'unionPartPath': unionPartPath
})
关于javascript - JSONata 获取父元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55976740/