[ 
https://issues.apache.org/jira/browse/NIFI-4456?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16446336#comment-16446336
 ] 

ASF GitHub Bot commented on NIFI-4456:
--------------------------------------

Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2640#discussion_r183161782
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/JsonRecordSetWriter.java
 ---
    @@ -64,18 +72,40 @@
             .defaultValue("false")
             .required(true)
             .build();
    +    static final PropertyDescriptor OUTPUT_GROUPING = new 
PropertyDescriptor.Builder()
    +            .name("output-grouping")
    +            .displayName("Output Grouping")
    +            .description("Specifies how the writer should output the JSON 
records (as an array or one object per line, e.g.) Note that if 'One Line Per 
Object' is "
    +                    + "selected, then Pretty Print JSON must be false.")
    +            .allowableValues(OUTPUT_ARRAY, OUTPUT_ONELINE)
    +            .defaultValue(OUTPUT_ARRAY.getValue())
    +            .required(true)
    +            .build();
     
         private volatile boolean prettyPrint;
         private volatile NullSuppression nullSuppression;
    +    private volatile OutputGrouping outputGrouping;
     
         @Override
         protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
             final List<PropertyDescriptor> properties = new 
ArrayList<>(super.getSupportedPropertyDescriptors());
             properties.add(PRETTY_PRINT_JSON);
             properties.add(SUPPRESS_NULLS);
    +        properties.add(OUTPUT_GROUPING);
             return properties;
         }
     
    +    @Override
    +    protected Collection<ValidationResult> 
customValidate(ValidationContext context) {
    +        final List<ValidationResult> problems = new 
ArrayList<>(super.customValidate(context));
    +        // Don't allow Pretty Print if One Line Per Object is selected
    +        if (context.getProperty(PRETTY_PRINT_JSON).asBoolean() && 
context.getProperty(OUTPUT_GROUPING).getValue().equals(OUTPUT_ONELINE.getValue()))
 {
    +            problems.add(new ValidationResult.Builder().input("Pretty 
Print").valid(false)
    +                    .explanation("Pretty Print JSON must be false when One 
Line Per Object is selected").build());
    --- End diff --
    
    Would recommend phrasing it something like "... when 'Output Grouping' is 
set to 'One Line Per Object'" to provide additional clarity


> Update JSON Record Reader / Writer to allow for 'json per line' format
> ----------------------------------------------------------------------
>
>                 Key: NIFI-4456
>                 URL: https://issues.apache.org/jira/browse/NIFI-4456
>             Project: Apache NiFi
>          Issue Type: Improvement
>          Components: Extensions
>            Reporter: Mark Payne
>            Assignee: Matt Burgess
>            Priority: Major
>
> It is common, especially for archiving purposes, to have many JSON objects 
> combined with new-lines in between, in order to delimit the records. It would 
> be useful to allow record readers and writers to support this, instead of 
> requiring that JSON records being elements in a JSON Array.
> For example, the following JSON Is considered two records:
> {code}
> [
>   { "greeting" : "hello", "id" : 1 },
>   { "greeting" : "good-bye", "id" : 2 }
> ]
> {code}
> It would be beneficial to also support the format:
> {code}
> { "greeting" : "hello", "id" : 1 }
> { "greeting" : "good-bye", "id" : 2 }
> {code}



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

Reply via email to