英文:
jolt transformation to check if a key has null value
问题
请帮助我进行jolt转换,以检查一个键是否具有空值。问题陈述如下。
对于TimeResolved
为null的输入,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转换中使用isNull和notNull函数,例如
[
{
"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": ""
}
}
]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论