json的Jolt转换-如何为空值添加移位操作

json的Jolt转换-如何为空值添加移位操作,json,transformation,jolt,Json,Transformation,Jolt,我有三个场景,分别是: 场景1:当“testInt”==10时,“isTrue”应设置为false,“testInt”设置为0和“testString” 输入 预期产量 场景2:当“testInt”==null时,应删除“testInt”,并删除其他内容 输入 预期产量 场景3:当进行“测试”!=10(也可以是非空)则无更改 输入 预期产量 如果有人建议我如何通过颠簸shift操作来实现这些,这将很有帮助。您可以定义这样的shift操作以及default操作,以便能够通过“null”到null转

我有三个场景,分别是:

场景1:
“testInt”==10
时,
“isTrue”
应设置为
false
“testInt”
设置为
0
“testString”

输入

预期产量

场景2:
“testInt”==null
时,应删除
“testInt”
,并删除其他内容

输入

预期产量

场景3:
进行“测试”!=10
(也可以是
非空
)则无更改

输入

预期产量


如果有人建议我如何通过颠簸shift操作来实现这些,这将很有帮助。

您可以定义这样的
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"
                }
            }
        }

    }
}]

其中
@(整数,键)
“@(2,testInt)”
“@(3,isTrue)”
表示开始搜索作为第二个参数显示的所需键的级别。这可以通过计算
“spec”:{
之后打开的大括号来计算,{除了
“spec”中的第一个
{
:{

感谢@barbaros-Özhan的回复,但是在场景2中,我没有得到我期望的输出。在这个“isTrue”中,我只得到了{“testString”:“testValue”)我正在努力解决这个问题,因为在我的例子中,我得到的是null而不是“null”.我没有找到任何处理null的解决方案,这在颠簸移位操作中不可能吗?@VikramKumar我通过默认操作添加了一个null转换。祝你好运。再次感谢你的快速回复,但还有一个限制,即如果任何字段为null,则应将其删除。这是在场景2中。非常感谢@barbaros-Özhan,最后,我得到了预期的输出。
{
"testString" :"testValue",
"testInt": 0,
"isTrue": false
}
{
"testString" :"testValue",
"testInt": null,
"isTrue": true
}
{
"testString" :"testValue",
"isTrue": true
}
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
{
"testString" :"testValue",
"testInt": 20,
"isTrue": true
}
[{
"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"
                }
            }
        }

    }
}]