简体   繁体   English

在 Nifi 中将单独的流文件与单独的 JSON 合并在一起

[英]Merge separate flow files with separate JSON together in Nifi

I am attempting to merge two flowfiles together using MergeContent.我正在尝试使用 MergeContent 将两个流文件合并在一起。 The content of both files are JSON objects which I would like to append to each other and wrap both with a JSON key.这两个文件的内容都是 JSON 对象,我想将它们 append 到对方,并用 JSON 密钥包装它们。

File 1:文件 1:

"Create":[
 {
   "Action": "Create",
   "Book": {
       "Id": "1234"
    }
 },
 {
   "Action": "Create",
   "Video": {
       "Id": 3245
   }
 }
]

File 2:文件 2:

"Update":[
 {
   "Action": "Update",
   "Book": {
       "Id": "5376"
    }
 },
 {
   "Action": "Update",
   "Video": {
       "Id": "8267"
   }
 }
]

I need the final output to look like so:我需要最终的 output 看起来像这样:

{
  "Transaction": {
    "Action": "Transaction",
    "Type": {
      "Create": [
        {fill in stuff}
      ],
      "Update": [
        {fill in stuff}
      ]      
    }
  }
}

What is happening is that my MergeContent processor is picking up more than one flow file out of the Update or Create input and it is merging 'like' flow files together, instead of merging the separate content together.发生的情况是,我的 MergeContent 处理器从更新或创建输入中拾取了多个流文件,并将“类似”流文件合并在一起,而不是将单独的内容合并在一起。

Screenshot of my MergeContent :我的 MergeContent 截图

在此处输入图像描述

You can add a MergeContent processor with您可以添加一个MergeContent处理器

  • Delimiter Strategy = Text Delimiter Strategy = Text
  • Header = { Header = {
  • Footer = } Footer = }
  • Demarcator = , Demarcator = ,

in order to generate the core part为了生成核心部分

      "Create": [
        {fill in stuff}
      ],
      "Update": [
        {fill in stuff}
      ]  

then apply a JSONJoltTransform with specification然后应用具有规范的JSONJoltTransform

[
  {
    "operation": "shift",
    "spec": {
      "#Transaction": "&.Action",
      "@": "Transaction.Type"
    }
  }
]

in order to convert them to a formatted JSON value as desired such as为了根据需要将它们转换为格式化的 JSON 值,例如

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM