Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Is there a way to iterate over array elements in Nifi?

avatar
Explorer

I have an array ["a,1", "b,2"]. I want to iterate over the array and form a JSON {"a":1, "b":2)


What's the best way to achieve this?

1 REPLY 1

avatar
Master Guru

@Karthik Gullapalli

You can use ExtractText processor to extract elements of Array then using Update attribute and ReplaceText processor we can create the final json.

Flow:

1.ExtractText //add new property with regex expression to extract a,1
2.ReplaceText //always replace as replacement strategy and use nifi expression language to prepare json.

(or)

Use the approach specified in this article 2.2 to iterate through array of elements and then use nifi expression language to create output flowfile in json format using ReplaceText processor.