- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
Nifi processor - route json array into multiple json arrays based on condition on json filed/attribute
- Labels:
-
Apache NiFi
-
Apache Ranger
Created ‎10-13-2016 02:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is there any Nifi processor to route mulitple json arrays(by splitting json array based on field/attribute condition) to multiple processor based on json field condition .
ex : assume [{a:1},{a:1},{a:2},{a:2}] is jsonarray , there is a requiremnt to route a=1 contained json files are send to another processor as array . and a=2 json array to another processor
Created on ‎10-13-2016 02:38 AM - edited ‎08-19-2019 02:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I hope I understand your question properly.
If you want to split the example JSON into two flow-files, each contains an array of elements with a=1, or a=2, then following flow can do the job. The point is passing the same JSON flow-file into two EvaluateJsonPath processors, then each EvaluateJsonPath extract array based on its own interest, using JSON path like '$.[?(@.a=='2')]'.
I've tested with an input JSON:
[{"a":1, "i": 1},{"a":1, "i": 2},{"a":2, "i": 3},{"a":2, "i": 4}]
Then, I got on left side:
[{"a":1,"i":1},{"a":1,"i":2}]
on right side:
[{"a":2,"i":3},{"a":2,"i":4}]
Hope this helps.
Created on ‎10-13-2016 02:38 AM - edited ‎08-19-2019 02:48 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I hope I understand your question properly.
If you want to split the example JSON into two flow-files, each contains an array of elements with a=1, or a=2, then following flow can do the job. The point is passing the same JSON flow-file into two EvaluateJsonPath processors, then each EvaluateJsonPath extract array based on its own interest, using JSON path like '$.[?(@.a=='2')]'.
I've tested with an input JSON:
[{"a":1, "i": 1},{"a":1, "i": 2},{"a":2, "i": 3},{"a":2, "i": 4}]
Then, I got on left side:
[{"a":1,"i":1},{"a":1,"i":2}]
on right side:
[{"a":2,"i":3},{"a":2,"i":4}]
Hope this helps.
Created ‎10-13-2016 02:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Another solution would be:
SplitJson -> EvaluateJsonPath (store a on attribute) -> RouteOnAttribute -> MergeContent
But if the desired output is JSON array, using EvaluateJsonPath is simpler.
Created ‎10-14-2016 07:57 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you . is it possible add 2 condition for content like a=='1 ' or a=='2' (or) a=='1' and i=='ss' . Thanks in advance
Created ‎10-15-2016 12:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
what is this expression languauge : $.[?(@.a...] , is it jave regex ? how can we use 2 values filter OR or AND for content filed ?? like a==1 or a==2 .
Created ‎10-17-2016 08:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello, sorry for the delay. The language is JSONPath. JSONPath itself has filtering capabilities. Many examples can be found on this page. https://github.com/jayway/JsonPath
Created ‎04-24-2020 07:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have some sort of the same scenario. But I have to route out on department value, like department="IT" route to some other flow and for department="DB" route to another flow.
For that, I have written out expression as $.[?(@.department=="DB")]. But this doesn't work. Please suggest for the above scenario.
And also if we have to apply some conditions like route data for a>10 like that.
Created ‎06-19-2017 04:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how to append values for empty flowfile attributes for JSON format data. i.e suppose i have 40 columns with JSON data consuming from kafka queue and i have values for 25 fields only and remaining 15 fields, i don't have values .So i put the json into EvaluateJsonPath processor and converted into flowfile attributes ..From some other processor i am getting values for those empty attributes so i need to append/fill the empty attributes with the values with orginal json file.
Can you please suggest how to use it?
thanks
