我正在使用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,第三个操作不出现.