简体   繁体   English

json 的颠簸变换 - 如何为 null 值添加移位操作

[英]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" != 10not 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM