请提供震动规格 输入json
[
{
"name": "Manu",
"age": 26,
"location": "New York",
"risk": "0"
},
{
"name": "Manju",
"age": 29,
"location": "New York city",
"risk": null
}
]
如果风险为 0,则风险级别为低;如果为空,则风险级别为空;如果风险为 1,则风险级别为高
[
{
"name": "Manu",
"age": 26,
"location": "New York",
"risklevel": "Low"
},
{
"name": "Manju",
"age": 29,
"location": "New York city",
"risklevel": null
}
]
尝试过的规格是:
[
{
"operation": "shift",
"spec": {
"*": {
"name": "[&1].name",
"age": "[&1].age",
"location": "[&1].location",
"risk": {
"0": {
"#Low": "[&2].risklevel"
},
"1": {
"#High": "[&2].risklevel"
},
"null": null,
"*": {
"@(2,risklevel)": "[&2].risklevel"
}
},
"*": "[&1].risklevel"
}
}
},
{
"operation": "default",
"spec": {
"*": {
"risklevel": "null"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"risklevel": "=toString"
}
}
}
]
您可以使用以下转换:
[//set an arbtrary value(say "NUll") to a null valued "risk"
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"~risk": "NUll"//occures whnever risk is null due to the ~ operator
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": "[&1].&", //the attributes other than "risk"
"risk": {
"1": { "#High": "[&3].riskLevel" },//hardcode by # operator
"0": { "#Low": "[&3].riskLevel" },
"NUll": { "@": "[&3].riskLevel" }
}
}
}
}
]
网站上的 演示 https://jolt-demo.appspot.com/ 是: