NiFi: trying to create record set from one field in and embedded array in JSON
I have this JSON:
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Herman Melville",
"title": "Moby **bleep**",
"isbn": "0-553-21311-3",
"price": 8.99
},
{
"category": "fiction",
"author": "J.R.R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
]
}I want a list/record set of categories. CSV, plain text, doesn't matter, but let's say CSV:
category
"refereces"
"fiction"
"fiction"I have tried many things, too many to repeat them all here. But basically, I have a GenerateFlowFile where the JSON is hard-coded, then a QueryReport where the reader is a JsonPathReader where I have properties for all fields in the JSON:
store $.store
book $.store.book[*]
category $.store.book[*].category
etc.Just to see what's being returned, I currently have the writer set to an all-defaults JsonRecordSetWriter.
With this in mind, in the QueryRecord, select * returns the JSON unaltered. select store returns the JSON unaltered. select book returns "no column named 'book'". I can use an EvaluateJsonPath with $.store.book[*].category as the property value, and it returns this:
["references", "fiction", "fiction"]If I switch over to an all-defaults CSVRecordSetWriter and do select store, I get this:
store
MapRecord[{book=[Ljava.lang.Object;@24bda2f0}]I know there are other ways to configure EvaluateJsonPath so it does parse the data correctly, but in doing so, it creates a FlowFile for each record. I don't want that; I want a single recordset in one FlowFile because this is just a proof of concept. With the real data I'm looking at tens of thousands of records.
I also know I could take this to Groovy and get it done. I'd like to avoid that and only use to the bare minimum of native NiFi processors.
I've also tried some things with a ForkRecord, but as I said, I've kind of lost the bubble on everything I've tried. I believe this is possible but running out of energy and ideas and think I've exhausted the wisdom of the web. Is it really this difficult?
Let me know what I'm doing wrong.



