[英]Jolt transformation of json - how to add shift operation for null value
I have three scenario which are:我有三个场景:
Scenario 1: When "testInt" == 10
then "isTrue"
should be set to false
and "testInt"
to 0
and "testString"
as it is.场景 1:当
"testInt" == 10
时, "isTrue"
应设置为false
, "testInt"
" 应设置为0
, "testString"
保持原样。
Input输入
{
"testString" :"testValue",
"testInt": 10,
"isTrue": true
}
Expected output预期 output
{
"testString" :"testValue",
"testInt": 0,
"isTrue": false
}
Scenario 2: When "testInt" == null
then "testInt"
should be removed and others as it is.场景 2:当
"testInt" == null
时, "testInt"
应该被删除,其他的应该被删除。
Input输入
{
"testString" :"testValue",
"testInt": null,
"isTrue": true
}
Expected output预期 output
{
"testString" :"testValue",
"isTrue": true
}
Scenario 3: When "testInt" != 10
(also not null
) then no changes.场景 3:当
"testInt" != 10
( not null
)时,没有变化。
Input输入
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
Expected output预期 output
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
It will be helpful if someone suggest me how to achieve these through jolt shift operation.如果有人建议我如何通过颠簸操作来实现这些,那将会很有帮助。
You can define such a shift
operation along with default
operation in order to be able to handle null
cases through "null"
to null
conversion您可以将这种
shift
操作与default
操作一起定义,以便能够通过"null"
到null
转换来处理null
案例
[{
"operation": "default",
"spec": {
"testInt": "null"
}
},{
"operation": "shift",
"spec": {
"testString": "testString",
"testInt": {
"10": {
"#0": "testInt"
},
"null": null,
"*": {
"@(2,testInt)": "testInt"
}
},
"isTrue": {
"@(2,testInt)": {
"10": {
"#false": "isTrue"
},
"*": {
"@(3,isTrue)": "isTrue"
}
}
}
}
}]
where @(integer,key)
such as "@(2,testInt)"
or "@(3,isTrue)"
representing the level going up to start search for the needed key presented as the second argument.其中
@(integer,key)
,例如"@(2,testInt)"
或"@(3,isTrue)"
表示开始搜索作为第二个参数呈现的所需键的级别。 That can be calculated by counting opening curly braces after "spec": {
except for this first {
within "spec": {
.这可以通过计算
"spec": {
除了第一个{
in "spec": {
spec": { 之后的左花括号来计算。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.