Support Questions
Find answers, ask questions, and share your expertise

NiFi: How to extract the size of a JSON array into an attribute?

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)?

1 ACCEPTED SOLUTION

Super Guru

@Patrick Hochstenbach

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.

View solution in original post

3 REPLIES 3

Super Guru

@Patrick Hochstenbach

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.

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.

Super Guru

@Patrick Hochstenbach

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.

Take a Tour of the Community
Don't have an account?
Your experience may be limited. Sign in to explore more.