I've looked around and haven't found a solution, or a denial that it can occur.
Most items I've seen relate to 2 JSON files that do not have the same format
which people want to merge.
My situation is different. Let's say that I have state/city JSON model
{"state":"California","city":"Sacramento"} and I can have multiple records for
a single state, but with different cities.
{"name":"StateCityList"
, "namespace": "nifi.statecitylist"
, "type": "record"
, "fields": [
{ "name": "state", "type": "string" }
, { "name": "city", "type":"string" }
]
}
I can use EvaluateJsonPath to put the state in as an attribute, and then Merge
Content to get a single FlowFile per state. This will produce a FlowFile with
multiple lines of that JSON model. What I've been trying to do is then send
that into a ConvertRecord that takes that JSON model as the input reader and
use an array as the sub-object to get an array of cities.
{"name":"StateCityList"
, "namespace": "nifi.statecitylist"
, "type": "record"
, "fields": [
{ "name": "state", "type": "string" }
, { "name": "city", "type": { "type": "array", "items": ["null","string"] } }
]
}
When I do this I get an error with "Cannot convert value [Sacramento] of type
java.lang.String to Object Array for field city." Is there something wrong with
my Avro schemas? Or is this just something that ConvertRecord (or MergeRecord)
can do?
Regarding the other things I've found relating to merging 2 separate JSON
objects, were using JoltTransformJSON or ExecuteScript with Groovy. Is this the
same situation for my scenario?
Thanks,
John McGinn