如何在Apache-NiFi中使用JoltTransformJson向现有数组添加属性

时间:2019-02-12 13:10:46

标签: apache-nifi jolt

如果输入是这样的:

{
"Vendor":[{"a":"..."},{"b":"..."}]
}

和属性是这样的:

{
"Vendor":[{"c":"..."},{"d":"..."}]
}

如何生成此输出:

{
"Vendor":[{"a":"..."},{"b":"..."},{"c":"..."},{"d":"..."}]
}

我认为joltTransformJson是最好的选择,但我无法生成所需的输出。

2 个答案:

答案 0 :(得分:0)

如何使用AttributesToJson处理器将属性放入内容,然后使用MergeContent处理器合并两个流文件呢?

答案 1 :(得分:0)

如果该属性被命名为json,则此方法应该起作用:

[
  {
    "operation": "default",
    "spec": {
     // extract vendor array from json attribute and put it in a temporary array
     "tempArray": ${json:jsonPath('$.Vendor')}
    }
  },
  {
    "operation": "shift",
    "spec": {
     "Vendor": "Vendor", // keep Vendor array as is
     "tempArray": { // put temp array elements inside Vendor
        "*": "Vendor"
     },
     "*": "&" // keep all of the other elements of the json 
    }
  }
]

我在评论中提供了解释,尽管json仍然有效,但不要忘记删除它们!