如果值不存在则设置为 null,否则 return 现有值(如果存在于 jolt 中)

Set null if value is not exists, otherwise return existing value if exists in jolt

如示例输入所示,我在每个对象中都有扩展数组。当扩展名不包含 subscription-type 时,输出应为空,如输出中所示,否则应包含现有值。同样适用于 language-typesubscription-typelanguage-type 的顺序本质上是随机的。

我试过使用 spec 但它不起作用

  {
    "operation": "modify-define-beta",
    "spec": {
      "*": {
        "subscriptionType": {
          "url": {
            "myCoercedValue": "subscription-type",
            "myStringValue": "subscription-type"
          },
          "value": {
            "myCoercedValue": null,
            "myStringValue": null
          }
        },
        "languageType": {
          "url": {
            "myCoercedValue": "language-type",
            "myStringValue": "language-type"
          },
          "value": {
            "myCoercedValue": null,
            "myStringValue": null
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "extension": "[&1].extension",
        "subscriptionType": "[&1].extension[]",
        "languageType": "[&1].extension[]"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "extension": {
          "*": {
            "@url": {
              "myStringValue": {
                "subscription-type": {
                  "@(3,value.myStringValue)": "[&3].subscriptionType[]"
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "0": "[]"
    }
  }
]

输入:

[
  {
    "extension": []
  },
  {
    "extension": [
      {
        "url": {
          "myCoercedValue": "subscription-type",
          "myStringValue": "subscription-type"
        },
        "value": {
          "myCoercedValue": "free",
          "myStringValue": "free"
        },
        "extension": []
      }
    ]
  },
  {
    "extension": [
      {
        "url": {
          "myCoercedValue": "language-type",
          "myStringValue": "language-type"
        },
        "value": {
          "myCoercedValue": "en-us",
          "myStringValue": "en-us"
        }
      },
      {
        "url": {
          "myCoercedValue": "subscription-type",
          "myStringValue": "subscription-type"
        },
        "value": {
          "myCoercedValue": "free",
          "myStringValue": "free"
        }
      }
    ]
  }
]

输出:

[ {
  "subscriptionType" : [ null, "free", "free" ],
  "language":[null,null,"en-US"]
} ]

或许你想要得到这样的结果?请尝试这些规范并说出您要修改的内容。

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "extension": {
          "*": {
            "url": {
              "myCoercedValue": {
                "subscription-type": {
                  "@(3,value)": {
                    "myCoercedValue": "subscriptionType[#8]"
                  }
                },
                "language-type": {
                  "@(3,value)": {
                    "myCoercedValue": "language[#8]"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]