How can I use “not equal” condition while filtering array using JOLT specification

不想你离开。 提交于 2019-12-11 15:28:51

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!