blob: e05d189afe9d7997902ddabcc635b3e2c2394974 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#pragma once
#include <Core/Block.h>
#include <IO/WriteBuffer.h>
#include <Processors/Formats/OutputFormatWithUTF8ValidationAdaptor.h>
#include <Formats/FormatSettings.h>
namespace DB
{
/** The stream for outputting data in JSON format, by object per line.
*/
class JSONEachRowRowOutputFormat : public RowOutputFormatWithUTF8ValidationAdaptor
{
public:
JSONEachRowRowOutputFormat(
WriteBuffer & out_,
const Block & header_,
const FormatSettings & settings_,
bool pretty_json_ = false);
String getName() const override { return "JSONEachRowRowOutputFormat"; }
/// Content-Type to set when sending HTTP response.
String getContentType() const override
{
return settings.json.array_of_rows ? "application/json; charset=UTF-8" : "application/x-ndjson; charset=UTF-8" ;
}
protected:
void writeField(const IColumn & column, const ISerialization & serialization, size_t row_num) override;
void writeFieldDelimiter() override;
void writeRowStartDelimiter() override;
void writeRowEndDelimiter() override;
void writeRowBetweenDelimiter() override;
void writePrefix() override;
void writeSuffix() override;
size_t field_number = 0;
bool pretty_json;
private:
Names fields;
FormatSettings settings;
};
}
|