使用 IF ELSE 时的颠簸转换将键映射到新键,并将这些替换用于新键值对
Jolt transformation while using IF ELSE map the keys to new keys and also use these replacement for new key value pair
我需要对下面的示例执行 Jolt 转换 json:
"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)"
}
}
}
}
]
我需要对下面的示例执行 Jolt 转换 json:
"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)"
}
}
}
}
]