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

Generate processors dynamically from JSON Object length

Solved Go to solution
Highlighted

Generate processors dynamically from JSON Object length

New Contributor

Hi, I just started with NiFi. I've been looking for two days without success the answer to my problem. There it goes:

I have a EvaluateJsonPath that returns into an JSON NiFi Attribute some objects id in that way : [0, 1, 2, 3, 4, 5, 6, ...]. I would wish to create a processor (InvokeHttp) for each id dynamically. After that, each created processor should take the id from the JSON to generate the url.

How do i face it?? Thank you so much.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Generate processors dynamically from JSON Object length

What you will want to do is split your original JSON into a flow file per id, and then send them all to a single InvokeHttp processor and reference a variable in URL of InvokeHttp. Here is a high-level of how it might work...

Lets say starting JSON is:

{ "ids" : [ "1", "2", "3" ] }

First use SplitJson processor with a Json Path of $.ids, this will produce 3 flow files where the content of each is 1, 2, and 3 respectively.

Second, use ExtractText processor.. add a user defined property with the name "my.id" and the value of (.*)

That will extract the content of each flow file into an attribute called my.id.

Finally, in InvokeHttp set the Remote URL to http://yourhost/path/${my.id}

When InvokeHttp processors a flow file, it will evaluate Remote URL against the incoming flow file attributes, and replace ${my.id} with the value of that attribute on the particular flow file, which in this case will be 1, 2, or 3.

View solution in original post

2 REPLIES 2
Highlighted

Re: Generate processors dynamically from JSON Object length

What you will want to do is split your original JSON into a flow file per id, and then send them all to a single InvokeHttp processor and reference a variable in URL of InvokeHttp. Here is a high-level of how it might work...

Lets say starting JSON is:

{ "ids" : [ "1", "2", "3" ] }

First use SplitJson processor with a Json Path of $.ids, this will produce 3 flow files where the content of each is 1, 2, and 3 respectively.

Second, use ExtractText processor.. add a user defined property with the name "my.id" and the value of (.*)

That will extract the content of each flow file into an attribute called my.id.

Finally, in InvokeHttp set the Remote URL to http://yourhost/path/${my.id}

When InvokeHttp processors a flow file, it will evaluate Remote URL against the incoming flow file attributes, and replace ${my.id} with the value of that attribute on the particular flow file, which in this case will be 1, 2, or 3.

View solution in original post

Highlighted

Re: Generate processors dynamically from JSON Object length

New Contributor

Thank you so much, @Bryan Bende. Your approach absolutely works!

Don't have an account?