简体   繁体   English

通过SplitJson和MergeContent过滤JSON

[英]Filter JSON via SplitJson and MergeContent

I'm building flow in nifi and in the flow I need to filter JSON by a filed. 我正在使用nifi构建流程,在流程中我需要通过字段过滤JSON。 So I decided to split json then merge filtered parts via SplitJson and MergeContent processors. 所以我决定拆分json然后通过SplitJson和MergeContent处理器合并过滤的部分。 My splitJson proccesor JsonPath is $.items[?(@.name =~ /.*Test.*/i)] so it splits correct but when I want to merge all parts into one json file (Merge Strategy = Defragment) and it merge files but incorrect way. 我的splitJson proccesor JsonPath是$.items[?(@.name =~ /.*Test.*/i)]所以它拆分正确但是当我想将所有部分合并成一个json文件(Merge Strategy = Defragment)它合并文件但方法不正确。 For example: 例如:

Input 输入

{ "items": [  { "name": "A" }, { "name": "B" }, { "name": "Test" }, { "name": "Test" } ] }

So I expect from MergeContent Processor this: 所以我期待MergeContent Processor这个:

[ {"name":"Test"}, {"name":"Test"} ]

but I got 但我明白了

{"name":"Test"}{"name":"Test"}

so this is even not a json 所以这甚至不是一个json

The ideal variant is to merge somehow: 理想的变体是以某种方式合并:

{ "items":[
{"name": "Test"},
{"name": "Test"}
]}

How to merge like this? 如何合并这样?

Configure MergeContent Processor as described below 如下所述配置MergeContent Processor

  • Delimiter Strategy as Text 作为Text分隔符策略

  • Header as [ 标题为[

  • Footer as ] 页脚]

  • Demarcator as , 划界者为,

Now your output flowfile from MergeContent processor will result as 现在,来自MergeContent处理器的输出流 MergeContent将生成为

[ {"name":"Test"}, {"name":"Test"} ]

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

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