jolt 转换以检查键是否具有空值

huangapple go评论100阅读模式
英文:

jolt transformation to check if a key has null value

问题

请帮助我进行jolt转换,以检查一个键是否具有空值。问题陈述如下。

对于TimeResolvednull输入severity将保持不变

{
  "parameterid": "Testing rule for event ID_Testing 1.0",
  "severity": 2,
  "TimeResolved": null
}

期望输出

{
  "parameterid": "Testing rule for event ID_Testing 1.0",
  "severity": 2,
  "TimeResolved": null
}

对于TimeResolved不为null输入severity将被更改为0

{
  "parameterid": "Testing rule for event ID_Testing 1.0",
  "severity": 2,
  "TimeResolved": 123456
}

期望输出是:

{
  "parameterid": "Testing rule for event ID_Testing 1.0",
  "severity": 0,
  "TimeResolved": null
}
英文:

Please help me in jolt transformation to check if a key has null value. The problem statement is mentioned as below.

For input where TimeResolved is null, severity will be as it is:

{
  "parameterid": "Testing rule for event ID_Testing 1.0",
  "severity": 2,
  "TimeResolved": null
}

expected output:

{
  "parameterid": "Testing rule for event ID_Testing 1.0",
  "severity": 2,
  "TimeResolved": null
}

For input where TimeResolved is not null, severity will be changed to 0:

{
  "parameterid": "Testing rule for event ID_Testing 1.0",
  "severity": 2,
  "TimeResolved": 123456
}

expected output is:

{
  "parameterid": "Testing rule for event ID_Testing 1.0",
  "severity": 0,
  "TimeResolved": null
}

答案1

得分: 1

您可以在modify-overwrite-beta转换中使用isNullnotNull函数,例如

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "NullCheck": ["=isNull(@(1,TimeResolved))", 0], // 如果TimeResolved不为空,则返回零
      "severity": "=notNull(@(1,NullCheck))", // 如果TimeResolved为空,则停止而不发出警告
      "TimeResolved": null // 在任何情况下都设置为null
    }
  },
  { // 去除"NullCheck"属性
    "operation": "remove",
    "spec": {
      "NullCheck": ""
    }
  }
]
英文:

You can use isNull and notNull functions within a modify-overwrite-beta transformation such as

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "NullCheck": ["=isNull(@(1,TimeResolved))", 0], // if TimeResolved is NOT NULL, then zero returns  
      "severity": "=notNull(@(1,NullCheck))", // stops silently if TimeResolved is NULL
      "TimeResolved": null // set to null in any case
    }
  },
  { // get rid of the "NullCheck" attribute
    "operation": "remove",
    "spec": {
      "NullCheck": ""
    }
  }
]

huangapple
  • 本文由 发表于 2023年8月4日 21:15:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76836288.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定