我想使用JSON
变换(条件为负)过滤JOLT
数组。在下面的示例中,我只希望记录URL
的值不等于Not Available.
{
"Photos": [
{
"Id": "327703",
"Caption": "TEST>> photo 1",
"Url": "Not Available."
},
{
"Id": "327704",
"Caption": "TEST>> photo 2",
"Url": "http://bob.com/0001/327704/photo.jpg"
},
{
"Id": "327705",
"Caption": "TEST>> photo 3",
"Url": "http://bob.com/0001/327705/photo.jpg"
}
]
}
答案 0 :(得分:0)
看看非常相似的问题Removing Elements from array based on a condition。基于它,您可以解决以下问题:
[
{
"operation": "shift",
"spec": {
"Photos": {
// loop thru all the photos
"*": {
// for each URL
"Url": {
// For "Not Available." do nothing.
"Not Available.": null,
// In other case pass thru
"*": {
"@2": "Photos[]"
}
}
}
}
}
}
]
通常,当您想取消过滤条件时,您需要进行过滤,并在转换通过null
时跳过项目。