[英]Jolt transformation while using IF ELSE map the keys to new keys and also use these replacement for new key value pair
I need to perform a Jolt transformation on the below example json:我需要对以下示例 json 执行颠簸转换:
"treasure": [
{
"name": "FOO",
"value": 45
},
{
"name": "BAR",
"value": 20
},
{
"name":"FOOBAR",
"value":23
]
I need the output to look like:我需要 output 看起来像:
{
"attributes" : {
"RAB" : 20,
"OOF" : 45,
"RABOOF":23
}
as you can see the BAR is replaced with RAB, FOO with OOF and FOOBAR replaced with RABOOF also used this replacement keys to map with the values in the input.如您所见,BAR 被 RAB 替换,FOO 被 OOF 替换,FOOBAR 被 RABOOF 替换,也使用了 map 的替换键和输入中的值。 I need to use a IF ELSE to make the replacement of the keys and also after replacing map the values to the keys accordingly What should be the spec here?我需要使用 IF ELSE 来替换键,并且在替换 map 之后,相应地键的值应该是什么?
This is how far I reached这就是我达到的程度
{
"operation": "shift",
"spec": {
"*": {
"treasure": {
"*": {
"name":{
"FOO":{
"#OOF":"treasure.name"
},
"BAR":{
"#RAB":"treasure.name"
},
"FOOBAR":{
"#RABOOF":"treasure.name"
}
}
}
},
"@(value)": "[&3].attributes.@(name)"
Check this spec,检查这个规格,
[
{
"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)"
}
}
}
}
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.