Member since
01-12-2018
10
Posts
1
Kudos Received
0
Solutions
01-19-2018
02:22 AM
3 Kudos
@Martin Mucha By using RouteOnContent processor we can check the contents of flowfile like is the flowfile message having array in it (or) not, if it is having array then you can route the flowfile to some processors, if not having array route to some other processors. Example:- Let's consider i'm having array of json messages and i'm splitting them individual messages Input:- [{"Id": "1","name":"HDP"},
{"Id": "2","name":"HDF"}] i'm having 2 json messages in an array and i need to add id,name values as attributes for this case i need to split the json array into individual flowfiles. SplitJSON:- JsonPath Expression
$.* this property will splits json array into individual flowfiles. For out input the output would be 2 flowfiles then i will use Evaljson path to extract attributes and add them to the flowfile. But i'm not sure everytime i will get json array (or) not, some times i get only single json message like {"Id": "1","name":"HDP"} for this input my splitjson processor won't give expected results. So for this case i'm going to use RouteOnContent processor:- to check the contents of flowfile and route them accordingly Case1:- if i get json array message then i need to route the flowfile to SplitJson processor. Configs:- Add new property as Array
^\[\{ //we are checking is the content starting with [ and followed by { that means it's an array of json messages in this case i'm going to transfer Array property relation to SplitJson processor. Case2:- if no data is in the json message then i'm checking with below property. NoData
^\{\} //checking the content having empty message in it i'm auto terminating this relation as we are not caring if there is no data. So now the unmatched relation will have single json messages i.e {"Id": "1","name":"HDP"} I'm routing this single json message to other processors(like EvalJsonPath..) to extract attribute values. RouteOnContent Configs:- Sample Flow:- Like this way you can check the contents of flowfile is content having arrays or not. for testing in the above example i'm just checking the starting characters of content, but you can check the whole contents of flowfiles by just adding new property with matching regex and change buffer size if needed. . If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.
... View more
01-15-2018
08:59 AM
Thanks a lot! This helped me, based on this hint everything works as it should. Thanks again. Martin.
... View more