Skip to content

Commit 8149793

Browse files
committed
JSON stream: support streaming a key-value pair to an object
Arrays already allow the equivalent operation, json_array_streamt::push_back(const jsont &)
1 parent 043ec72 commit 8149793

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/util/json_stream.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ class json_stream_objectt : public json_streamt
169169
return it->second;
170170
}
171171

172+
/// Push back a JSON element into the current array stream.
173+
/// Provided for compatibility with `jsont`.
174+
/// \param json: a non-streaming JSON element
175+
void push_back(const std::string &key, const jsont &json)
176+
{
177+
PRECONDITION(open);
178+
// To ensure consistency of the output, we flush and
179+
// close the current child stream before printing the given element.
180+
output_child_stream();
181+
output_delimiter();
182+
jsont::output_key(out, key);
183+
json.output_rec(out, indent + 1);
184+
}
185+
172186
json_stream_objectt &push_back_stream_object(const std::string &key);
173187
json_stream_arrayt &push_back_stream_array(const std::string &key);
174188

0 commit comments

Comments
 (0)