问题描述
我有以下三种情况:
场景 1: 当 "testInt" == 10
时,"isTrue"
应设置为 false
,"testInt"
应设置为 0
和 {{1 }} 原样。
输入
"testString"
预期输出
{
"testString" :"testValue","testInt": 10,"isTrue": true
}
场景 2:当 {
"testString" :"testValue","testInt": 0,"isTrue": false
}
时,"testInt" == null
应该被删除,其他人则保持原样。
输入
"testInt"
预期输出
{
"testString" :"testValue","testInt": null,"isTrue": true
}
场景 3:当 {
"testString" :"testValue","isTrue": true
}
(也"testInt" != 10
)时没有变化。
输入
not null
预期输出
{
"testString" :"testValue","testInt": 20,"isTrue": true
}
如果有人建议我如何通过 jolt 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"
}
}
}
}
}]
其中 @(integer,key)
如 "@(2,testInt)"
或 "@(3,isTrue)"
表示上升到开始搜索作为第二个参数提供的所需键的级别。这可以通过计算 "spec": {
之后的左花括号来计算,除了 {
中的第一个 "spec": {
。