[ 
https://issues.apache.org/jira/browse/NIFI-5093?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matt Forrester updated NIFI-5093:
---------------------------------
    Description: 
ConvertAvroToJson does not follow the expectations of anyone who knows JSON or 
JavaScript when there are zero Avro records coming from upstream. For a zero 
length sequence the outputs are:


JSON Container Options: array
Wrap Single Record: false
Result: {}
Expected Result: ''
Why is this wrong?: This has not been wrapped in an array as specified and in 
any no items were sent from upstream, not one item with zero fields


JSON Container Options: array
Wrap Single Record: true
Result: [{}]
Expected Result: '[]'
Why is this wrong?: This is one item with no fields that was never sent from 
the upstream.


JSON Container Options: none
Wrap Single Record: false
Result: ''
Why is this wrong?: This is one item with no fields that was never sent from 
the upstream.


JSON Container Options: none
Wrap Single Record: true
Result: ''
Why is this wrong? This is one item with no fields that was never sent from the 
upstream.


IMHO these options are specifying two things for what should actually be one 
thing. In JSON, which is a subset of JavaScript an Object is represented as {} 
and an Array is represented as [].

If you have a stream of objects they could either:

* Be wrapped in '[]', so the whole document is valid JSON, for example '[]' or 
'[\{"name":"ben"},\{"name":"jane"}]'

* Formatted as NDJSON which would be '' or 
'\{"name":"ben"}\n\{"name":"jane"}\n' where every line is valid JSON (unless 
zero length)

  was:
ConvertAvroToJson with the options
 * JSON Container Options: None
 * Wrap Single Record: False

Given 1+ Avro records from ExecuteSQL it creates a newline delimited list of 
object, which is great (and looks like [http://ndjson.org/)]

Given 0 records it creates a list of one empty object.

This is not helpful as any downstream processor which is expecting JSON with 
specific fields will fail.

NDJSON is cool as it's a streamable format and we should enable easy usage.

To be fair, this is all documented but it's rather strange. An NDJSON file with 
no records should probably be zero bytes in length.


> ConvertAvroToJson
> -----------------
>
>                 Key: NIFI-5093
>                 URL: https://issues.apache.org/jira/browse/NIFI-5093
>             Project: Apache NiFi
>          Issue Type: Bug
>    Affects Versions: 1.6.0
>         Environment: Ubuntu / Chromium
>            Reporter: Matt Forrester
>            Priority: Minor
>
> ConvertAvroToJson does not follow the expectations of anyone who knows JSON 
> or JavaScript when there are zero Avro records coming from upstream. For a 
> zero length sequence the outputs are:
> JSON Container Options: array
> Wrap Single Record: false
> Result: {}
> Expected Result: ''
> Why is this wrong?: This has not been wrapped in an array as specified and in 
> any no items were sent from upstream, not one item with zero fields
> JSON Container Options: array
> Wrap Single Record: true
> Result: [{}]
> Expected Result: '[]'
> Why is this wrong?: This is one item with no fields that was never sent from 
> the upstream.
> JSON Container Options: none
> Wrap Single Record: false
> Result: ''
> Why is this wrong?: This is one item with no fields that was never sent from 
> the upstream.
> JSON Container Options: none
> Wrap Single Record: true
> Result: ''
> Why is this wrong? This is one item with no fields that was never sent from 
> the upstream.
> IMHO these options are specifying two things for what should actually be one 
> thing. In JSON, which is a subset of JavaScript an Object is represented as 
> {} and an Array is represented as [].
> If you have a stream of objects they could either:
> * Be wrapped in '[]', so the whole document is valid JSON, for example '[]' 
> or '[\{"name":"ben"},\{"name":"jane"}]'
> * Formatted as NDJSON which would be '' or 
> '\{"name":"ben"}\n\{"name":"jane"}\n' where every line is valid JSON (unless 
> zero length)



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to