private JsonGenerator createGenerator() {
        JsonGenerator jsonGenerator;
        try {
            jsonGenerator = jsonFactory.createGenerator(new IgnoreCloseWriter(getWriter()));
            if (indentOutput) {
                jsonGenerator.useDefaultPrettyPrinter();
            }

            // Configure the jsonGenerator to add a root value separator unless
            // we want trailing ones in which case we will add them ourselves on
            // endElement().
            if (addTrailingRootValueSeparator) {
                jsonGenerator.setRootValueSeparator(null);
            } else {
                jsonGenerator.setRootValueSeparator(new SerializedString(rootValueSeparator));
            }
        } catch (final IOException | RuntimeException e) {
            fatal(e);
            throw LoggedException.wrap(e);
        }

        return jsonGenerator;
    }
Writes out XML and records segment boundaries as it goes.
stroom-pipeline/src/main/java/stroom/pipeline/writer/JSONWriter.java