diff --git a/output/src/main/java/com/scottlogic/datahelix/generator/output/writer/json/JsonOutputWriterFactory.java b/output/src/main/java/com/scottlogic/datahelix/generator/output/writer/json/JsonOutputWriterFactory.java index 9feedbc35..fb631f3e4 100644 --- a/output/src/main/java/com/scottlogic/datahelix/generator/output/writer/json/JsonOutputWriterFactory.java +++ b/output/src/main/java/com/scottlogic/datahelix/generator/output/writer/json/JsonOutputWriterFactory.java @@ -16,7 +16,9 @@ package com.scottlogic.datahelix.generator.output.writer.json; +import com.fasterxml.jackson.core.PrettyPrinter; import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; +import com.fasterxml.jackson.core.util.MinimalPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SequenceWriter; @@ -41,7 +43,10 @@ public JsonOutputWriterFactory(@Named("config:streamOutput") boolean streamOutpu @Override public DataSetWriter createWriter(OutputStream stream, Fields fields) throws IOException { - ObjectWriter objectWriter = new ObjectMapper().writer(new DefaultPrettyPrinter(NEW_LINE_DELIMITER)); + PrettyPrinter prettyPrinter = streamOutput + ? new MinimalPrettyPrinter(NEW_LINE_DELIMITER) + : new DefaultPrettyPrinter(); + ObjectWriter objectWriter = new ObjectMapper().writer(prettyPrinter); SequenceWriter writer = objectWriter.writeValues(stream); writer.init(!streamOutput); diff --git a/output/src/test/java/com/scottlogic/datahelix/generator/output/writer/json/JsonOutputWriterFactoryTest.java b/output/src/test/java/com/scottlogic/datahelix/generator/output/writer/json/JsonOutputWriterFactoryTest.java index b653d48a0..5a4bb8447 100644 --- a/output/src/test/java/com/scottlogic/datahelix/generator/output/writer/json/JsonOutputWriterFactoryTest.java +++ b/output/src/test/java/com/scottlogic/datahelix/generator/output/writer/json/JsonOutputWriterFactoryTest.java @@ -44,7 +44,7 @@ void writer_whereStreamingJson__shouldOutputNewLineDelimiterRows() throws IOExce expectJson( fields, true, - Matchers.equalTo("{\n \"my_field\" : \"my_value\"\n}\n{\n \"my_field\" : \"my_value\"\n}")); + Matchers.equalTo("{\"my_field\":\"my_value\"}\n{\"my_field\":\"my_value\"}")); } @Test @@ -68,7 +68,7 @@ void writeRow_withInternalFields_shouldNotWriteInternalFields() throws IOExcepti expectJson( fields, true, - Matchers.equalTo("{\n \"External\" : \"my_value\"\n}\n{\n \"External\" : \"my_value\"\n}") + Matchers.equalTo("{\"External\":\"my_value\"}\n{\"External\":\"my_value\"}") ); }