使用IFELSE时的Jolt转换将键映射到新的键,并使用这些替换来替换新的键值对



我需要对以下示例json:执行Jolt转换

"treasure": [
{
"name": "FOO",
"value": 45
},
{
"name": "BAR",
"value": 20
},
{
"name":"FOOBAR",
"value":23
]

我需要输出看起来像:

{
"attributes" : {
"RAB" : 20,
"OOF" : 45,
"RABOOF":23
}

正如你所看到的,BAR被RAB替换,FOO被OOF替换,FOOBAR被RABOOF替换也使用了这个替换键来映射输入中的值。我需要使用IF ELSE来替换键,并且在替换后将值相应地映射到键这里的规格应该是什么?

这就是我到达的距离

{
"operation": "shift",
"spec": {
"*": {
"treasure": {
"*": {
"name":{
"FOO":{
"#OOF":"treasure.name"
},
"BAR":{
"#RAB":"treasure.name"
},
"FOOBAR":{
"#RABOOF":"treasure.name"
}
}

}
},
"@(value)": "[&3].attributes.@(name)"


检查此规范,

[
{
"operation": "shift",
"spec": {
"treasure": {
"*": {
"name": {
"FOO": {
"#OOF": "treasure[&3].name",
"@(2,value)": "treasure[&3].value"
},
"BAR": {
"#RAB": "treasure[&3].name",
"@(2,value)": "treasure[&3].value"
},
"FOOBAR": {
"#RABOOF": "treasure[&3].name",
"@(2,value)": "treasure[&3].value"
}
}
}
}
}
}, {
"operation": "shift",
"spec": {
"treasure": {
"*": {
"@(0,value)": "attributes.@(1,name)"
}
}
}
}
]

最新更新