仅在JOLT中字段不为空时如何映射

时间:2018-07-31 09:28:07

标签: jolt

这是我的输入内容:

   { "isPoolPoint": "test", "timeZone": "ET" }

我希望输出为:

   { "address" : [{"line2": "test"}] }

如果isPoolPointnull,我应该不会得到任何输出。

2 个答案:

答案 0 :(得分:0)

规格

[
  {
    "operation": "shift",
    "spec": {
      "isPoolPoint": {
        // match down into the values of "isPoolPoint"
        // if we match null, then do nothing
        "null": null,
        // match everything else
        "*": {
          // write what was matched to the output
          "$": "address[0].line2"
        }
      }
    }
  }
]

答案 1 :(得分:0)

I wanted to ignore blank strings as well in addition to null values so I did below extra condition

[
  {
    "operation": "shift",
    "spec": {
      "isPoolPoint": {
         // OR operator below will care of empty string or null
        "|null": null,
        "*": {
          "$": "address[0].line2"
        }
      }
    }
  }
]