MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / jsonElementToString

Function jsonElementToString

src/Formats/JSONExtractTree.cpp:70–133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68
69template <typename JSONParser>
70void jsonElementToString(const typename JSONParser::Element & element, WriteBuffer & buf, const FormatSettings & format_settings)
71{
72 if (element.isInt64())
73 {
74 writeIntText(element.getInt64(), buf);
75 return;
76 }
77 if (element.isUInt64())
78 {
79 writeIntText(element.getUInt64(), buf);
80 return;
81 }
82 if (element.isDouble())
83 {
84 writeFloatText(element.getDouble(), buf);
85 return;
86 }
87 if (element.isBool())
88 {
89 if (element.getBool())
90 writeCString("true", buf);
91 else
92 writeCString("false", buf);
93 return;
94 }
95 if (element.isString())
96 {
97 writeJSONString(element.getString(), buf, format_settings);
98 return;
99 }
100 if (element.isArray())
101 {
102 writeChar('[', buf);
103 bool need_comma = false;
104 for (auto value : element.getArray())
105 {
106 if (std::exchange(need_comma, true))
107 writeChar(',', buf);
108 jsonElementToString<JSONParser>(value, buf, format_settings);
109 }
110 writeChar(']', buf);
111 return;
112 }
113 if (element.isObject())
114 {
115 writeChar('{', buf);
116 bool need_comma = false;
117 for (auto [key, value] : element.getObject())
118 {
119 if (std::exchange(need_comma, true))
120 writeChar(',', buf);
121 writeJSONString(key, buf, format_settings);
122 writeChar(':', buf);
123 jsonElementToString<JSONParser>(value, buf, format_settings);
124 }
125 writeChar('}', buf);
126 return;
127 }

Callers

nothing calls this directly

Calls 15

writeIntTextFunction · 0.85
writeJSONStringFunction · 0.85
writeCharFunction · 0.85
writeFloatTextFunction · 0.50
isInt64Method · 0.45
getInt64Method · 0.45
isUInt64Method · 0.45
getUInt64Method · 0.45
isDoubleMethod · 0.45
getDoubleMethod · 0.45
isBoolMethod · 0.45
getBoolMethod · 0.45

Tested by

no test coverage detected