使用 JOLT 规范过滤数组时如何使用 "not equal" 条件
How can I use "not equal" condition while filtering array using JOLT specification
我想使用 JOLT
转换过滤 JSON
数组,其中条件为负。在下面的示例中,我只想要 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"
}
]
}
查看非常相似的问题 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
跳过项目。
我想使用 JOLT
转换过滤 JSON
数组,其中条件为负。在下面的示例中,我只想要 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"
}
]
}
查看非常相似的问题 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
跳过项目。