Support Questions

Find answers, ask questions, and share your expertise

Who agreed with this solution

avatar
Super Guru

Hi @noncitizen ,

I think using  JsonPathReader is not the right choice for this requirement. This service according to the documentation will always evaluate against the root element:

"...If the root of the FlowFile's JSON is a JSON Array, each JSON Object found in that array will be treated as a separate Record, not as a single record made up of an array. If the root of the FlowFile's JSON is a JSON Object, it will be evaluated as a single Record..."

ref: https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-record-serialization-services...

So since your root element "store" is an object it will always return a single record , and if it happens that one of the fields is an array , it will be returned as a single record as an array representation:

["references", "fiction", "fiction"]

It seems the JsonPathReader is more suited when your root element is an array. If you want to make it work so that it returns multiple records you probably need to do jolt transformation to dump all book array items into root array. Keep in mind if you want just the category or any other certain field you have to define an Avro schema with the expected fields otherwise all none specified fields will be returned with blank values.

What you need is JsonTreeReader service instead where its configured to use Nested Field as Starting Field Strategy, then specify "book" as the Starting Field Name, as follows:

SAMSAL_0-1706609795720.png

The QueryRecord then simply can be configured as follows:

SAMSAL_1-1706609912610.png

which will give you desired output in CSV format:

category
reference
fiction
fiction

If that helps please accept solution.

Thanks

 

View solution in original post

Who agreed with this solution