我使用kazaam模块来定义json转换。https://github.com/qntfy/kazaam
这是我的规则:
"rules": [
{
"operation": "shift",
"spec": {
"Shift": "instruction.context.example1"
}
},
{
"operation": "concat",
"spec": {
"sources": [
{
"path": "instruction.context.example1"
},
{
"path": "instruction.context.example2"
}
],
"targetPath": "Concat",
"delim": "_"
}
},
{
"operation": "coalesce",
"spec": {
"Coalesce": [
"instruction.context.example3[0].id"
]
}
}
]
字符串
适用于此JSON:
{
"instruction": {
"context": {
"example1": "example1 value",
"example2": "example2 value",
"example3": [
{
"id": "example3_1_value"
},
{
"id": "example3_2_value"
},
{
"id": "example3_3_value"
}
]
}
}
}
型
结果是这样的:
{
"Shift": "example1 value",
"Concat": "null_null"
}
型
所以第一个操作有效,第二个返回null_null,第三个不出现。
1条答案
按热度按时间avwztpqn1#
规则一个接一个地被应用。你的第一个规则产生的东西作为输入被输入到你的第二个规则,依此类推,它们被链接起来。所以,你的第一个转换产生了一个对象:
字符串
当上面的内容作为第二个操作的输入时,你得到的是
null
值,因为你引用的字段不存在。您可以尝试将第一条规则更改为:
型
看看它的效果