Hi,

I am struggling with ConvertAvroToJson and have opened a ticket #5093.

I have developed/hacked what is practically a replacement of this processor
at ( https://github.com/forbesmyester/NiFi-ConvertAvroToClassicJSON )
because I struggle to see how in it's current state does not force strange
code on anything which receives it's output.

You can configure this processor with two options, with the first value
being the default:

 * JSON container options: array/none
 * Wrap Single Record: false/true

Below are sample outputs for all possible options when encoding either some
items in a set, or an empty set.

## Array / True
Empty: `[{}]`
Some: `[{"name": "Ted", "age": 21},{"name": "Sam", "age": 19}]`

## Array / False
Empty: `{}`
Some: `[{"name": "Ted", "age": 21},{"name": "Sam", "age": 19}]`

## None / True
Empty: `{}`
Some: `{"name": "Ted", "age": 21}\n{"name": "Sam", "age": 19}`

## None / False
Empty: `{}`
Some: `{"name": "Ted", "age": 21}\n{"name": "Sam", "age": 19}`

If I wanted to write code that receives and processes this data I would
probably say that all are not very helpful, requiring me to filter out
wierd empty objects. The second option is a complete nightmare because it
returns different types depending on if there are any items or not.

It seems to me the biggest problem is the insertion of empty objects into
the output when the result is zero length.

Would it be reasonable to add a configuration option called "Zero length
output handling" with the options of either `Inject Empty Object` (default)
or `Leave zero length`. When the `Leave zero length` option is selected it
would change the output to the following:

## Array / True / Leave Zero Length
Empty: `[]`
Some: `[{"name": "Ted", "age": 21},{"name": "Sam", "age": 19}]`

## Array / False / Leave Zero Length
Empty: ``
Some: `[{"name": "Ted", "age": 21},{"name": "Sam", "age": 19}]`

## None / True / Leave Zero Length
Empty: ``
Some: `{"name": "Ted", "age": 21}\n{"name": "Sam", "age": 19}`

## None / False / Leave Zero Length
Empty: ``
Some: `{"name": "Ted", "age": 21}\n{"name": "Sam", "age": 19}`

With the option `Inject Empty Object` is selected the output would be
identical to what is now returned.

If these changes were made (I am prepared to submit a PR) it would at least
be possible to write code which consumes the result without ugly hacks,
depending on selections made.

I am however open to other suggestions for fixing this and would probably
still be happy to prepare the PR.

Thanks

Matt Forrester

Reply via email to