Qore json Module 1.11.0
Loading...
Searching...
No Matches
NdjsonDataProvider::NdjsonWriter Class Reference

Writer for creating NDJSON (Newline Delimited JSON) output. More...

#include <NdjsonWriter.qc.dox.h>

Inheritance diagram for NdjsonDataProvider::NdjsonWriter:
NdjsonDataProvider::NdjsonStringWriter

Public Member Methods

void constructor (Qore::OutputStream output_stream, soft< hash< NdjsonWriterOptions > > options)
 Creates the writer with an output stream.
 
int write (auto value)
 Writes a JSON value as a line.
 
int writeAll (list< auto > values)
 Writes multiple JSON values as lines.
 
int getRecordsWritten ()
 Returns the number of records written.
 

Private Attributes

Qore::StreamWriter writer
 The output stream.
 
string line_ending
 Line ending string.
 
hash< NdjsonWriterOptionsopts
 Writer options.
 

Detailed Description

Writer for creating NDJSON (Newline Delimited JSON) output.

This class provides methods for writing JSON values in NDJSON format to an output stream.

Example
StringOutputStream sos();
NdjsonWriter writer(sos);
writer.write({"name": "Alice", "age": 30});
writer.write({"name": "Bob", "age": 25});
string result = sos.getData();
# result is: {"name":"Alice","age":30}\n{"name":"Bob","age":25}\n

Member Function Documentation

◆ constructor()

void NdjsonDataProvider::NdjsonWriter::constructor ( Qore::OutputStream  output_stream,
soft< hash< NdjsonWriterOptions > >  options 
)

Creates the writer with an output stream.

Parameters
output_streamthe output stream to write to
optionswriter options

◆ write()

int NdjsonDataProvider::NdjsonWriter::write ( auto  value)

Writes a JSON value as a line.

Parameters
valuethe value to serialize as JSON and write
Returns
the number of bytes written

◆ writeAll()

int NdjsonDataProvider::NdjsonWriter::writeAll ( list< auto >  values)

Writes multiple JSON values as lines.

Parameters
valuesthe list of values to write
Returns
the total number of bytes written

The documentation for this class was generated from the following file: