apache-nifi - Apache Nifi - 拆分数组并格式化为 JSON?
问题描述
可能是一个简单的初学者问题:
使用 NIFI,我想以以下形式拆分一个数组(表示 flowfile-content)
["x1","x2", ..]
并将其格式化为表单的 JSON 对象
{"key1":"x1", "key2":"x2", ..}
(也作为流文件内容)
使用什么处理器最有效,表达式脚本会是什么样子?
提前致谢, 马克
解决方案
通过使用JoltTransformJSON处理器应用Jolt转换可能是一个不错的选择。在其中,您可以通过单击“配置处理器”对话框的“设置”选项卡中所述的“高级”按钮在下面添加这样的规范:
[
//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)"
}
}
]
推荐阅读
- javascript - 如果我在最新版本的 Angular 中构建组件,该组件是否可以被使用早期 Angular 版本构建的应用程序使用?
- r - 获取一段时间内的累积值计数
- hibernate - 有没有办法将自然键作为应用程序上下文的键?
- html - 有没有办法对齐按钮,使其不会一直向右?
- c++ - 无法在子命名空间中为派生类实现方法
- java - N-Ary 树的 Java 级别顺序(迭代而不是递归)
- oracle - 如何解决 OWBSYS 用户中无效的 JAVA CLASS
- dimensions - scipy.optimize.minimize 中的维度问题
- c++ - 为什么此示例使用 memcpy 将 uint8_t* 参数转换为结构?
- css - 使用边框半径时,在 Safari 中首次加载时,阴影不会显示在侧面