Apache Nifi-拆分数组并格式化为JSON



可能是一个简单的初学者问题:

使用NIFI,我想以的形式拆分数组(表示流文件内容(

["x1","x2", ..]

并将其格式化为形式的JSON对象

{"key1":"x1", "key2":"x2", ..}

(也称为流文件内容(

使用的处理器效率最高,表达式脚本会是什么样子?

提前感谢,Marc

通过使用JoltTransformJSON处理器来应用Jolt转换可能是一个不错的选择。在其中,您可以通过单击ADVANCED按钮添加这样的规范,该按钮在配置处理器对话框的>设置选项卡中说明:

[
//Determine respective lists to be used to calculate their sizes within the next step 
//in order to get ordinals for the key values
{
"operation": "shift",
"spec": {
"*": {
"*": "&(0,0).[#2]"
}
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"*": "=size(@(1,&))"
}
},
//exchange key and values
{
"operation": "shift",
"spec": {
"*": {
"$": "@(0)"
}
}
},
//add the desired word such as "key"
{
"operation": "shift",
"spec": {
"*": "key&(0,0)"
}
}
]

最新更新