- 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: How to extract the size of a JSON array into an attribute?
- Labels:
-
Apache NiFi
Created 05-29-2019 02:14 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In my flow file I have JSON content which contains an array. How can I extract the size of that array into an attribute (e.g. my.array.size = 5)?
Created 05-30-2019 01:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use SplitJson processor to split the array($.*) into individual flowfile then split json processor adds fragment.count attribute to the flowfile which is array size.
Use UpdateAttribute processor to change the attribute name.
Use MergeContent processor to merge back the content using Defragment strategy.
Created 05-30-2019 01:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use SplitJson processor to split the array($.*) into individual flowfile then split json processor adds fragment.count attribute to the flowfile which is array size.
Use UpdateAttribute processor to change the attribute name.
Use MergeContent processor to merge back the content using Defragment strategy.
Created 06-03-2019 07:07 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, I was hoping for an easy trick because I needed many of these calculations. Maybe I need to write a custom processor for this.
Created 06-04-2019 02:58 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes,You can consider custom processor/custom script for this, to do this in easier way and add the attribute to the flowfile with array size.
Created 10-13-2022 12:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You can use EvaluateJsonPath. You only have to add an extra attribute and name it as you want (e.g. count) and set as value "$.my.array.size.length()". Then select Destination and change it to flowfile-attribute. This processor will produce a flowfile which has your extra attribute
