Check if null or empty in jolt and put another value which is present in input JSON

ぐ巨炮叔叔 提交于 2019-12-06 12:10:36

Can do that with "modify-default". Modify-default will only fill in a value if a key does not exist or it's value is null.

Spec

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "shipping_address": {
        "address": "@(2,payment_address.address)"
      }
    }
  }
]

Input A, where there is not shipping address

{
  "payment_address": {
    "address": "some address"
  },
  "shipping_address": {}
}

Produces output A, where the billing address is copied over

{
  "payment_address" : {
    "address" : "some address"
  },
  "shipping_address" : {
    "address" : "some address"
  }
}

Input B, where there is a shipping_address

{
  "payment_address": {
    "address": "some address"
  },
  "shipping_address": {
    "address": 1234
  }
}

Produces output B, where the shipping address does not get overwritten.

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