我正在寻找 JOLT 转换,以用其实体替换引用:
我的输入如下:
{
"users": [
{
"id": 1,
"firstname": "Max"
},
{
"id": 4,
"firstname": "Mel"
}
],
"special-role": {
"id": 4
}
}
我的预期输出应该是:
{
"special-role" : {
"firstname": "Mel"
}
}
SO 上已经有一个示例关于映射参考的 JOLT 转换问题但我无论如何也无法找到解决问题的方法。我还没找到如何用
"@(2,users.4.firstname)": "&"
下的值替换
"special-role": { "id": 4 }
中的固定值“4”
我对规范的最新尝试是:
[
{
"operation": "shift",
"spec": {
"users": {
"*": {
"*": "&2.@(1,id).&"
}
},
"special-role": "&"
}
},
{
"operation": "shift",
"spec": {
"special-role": {
"id": {
"@(2,users.4.firstname)": "&"
}
}
}
}
]
special-role
( @(2,&) ) 在
第二次变身所以,你可以使用:
[
{
"operation": "shift",
"spec": {
"users": {
"*": {
"fir*": "@(1,id).&" // pick the attribute "firstname" only
}
},
"*": { // case of "special-role"
"*": "&1"
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"@(2,&)": "&2"
}
}
}
}
]
网站上的 演示 http://jolt-demo.appspot.com/ 是: