Created 01-30-2024 02:26 AM
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..."
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:
The QueryRecord then simply can be configured as follows:
which will give you desired output in CSV format:
category
reference
fiction
fiction
If that helps please accept solution.
Thanks