NiFi JOLT转换规范需求:合并双键为单键并指定值来源
正确的NiFi JOLT转换规范
输入示例
{ "options": [ { "method": "GET", "type": "USER", "flag": true, "updateSource": "DB" }, { "method": "POST", "type": "ORDER", "flag": false, "updateSource": "API" } ] }
目标输出示例
{ "GET_USER": true, "GET_USER_updateSource": "DB", "POST_ORDER": false, "POST_ORDER_updateSource": "API" }
JOLT转换规范
[ { "operation": "shift", "spec": { "options": { "*": { "flag": "@(1,method)_@(1,type)", "updateSource": "@(1,method)_@(1,type)_updateSource" } } } }, { "operation": "remove", "spec": { "options": "" } } ]
转换逻辑说明
shift操作遍历options数组的每个元素:- 通过
@(1,method)_@(1,type)拼接出method_type格式的键,将flag的值映射到该键下 - 拼接
method_type_updateSource格式的键,将updateSource的值映射到对应键下
- 通过
remove操作清理原有的options数组,仅保留转换后的目标键值对
内容的提问来源于stack exchange,提问作者Sam
相关产品推荐
相关产品推荐

