问题
I want to filter JSON
array using JOLT
transformation, where condition is negative. In the below example I want only records where URL
value is not equal to 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"
}
]
}
回答1:
Take a look on very similar question Removing Elements from array based on a condition. Based on it you can solve it as below:
[
{
"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[]"
}
}
}
}
}
}
]
Generally when you want to negate filter you do a filter and as transformation pass null
which skips item.
来源:https://stackoverflow.com/questions/54874578/how-can-i-use-not-equal-condition-while-filtering-array-using-jolt-specificati