src/v/serde/json/README.md
serde/json provides a Seastar-friendly streaming JSON parser. Low level
parsing routines (string, numeric) are ported from RapidJSON and redesigned
for incremental parsing. As a result, the parser can be used to parse JSON
documents incrementally, i.e. the input buffer can be split into multiple chunks
with arbitrary alignment/boundaries.
StAX (Streaming API for XML) style API is used to parse JSON documents.
auto p = serde::json::parser(iobuf);
while (co_await p.next()) {
switch (p.token()) {
case serde::json::token::object_start:
// handle object start
break;
// ... handle other token types
}
}
Push-parsers are our solution for asynchronous incremental parsing.
Pros:
co_await for every byte read (e.g., if parsing is implemented
from seastar::input_stream).seastar::temporary_buffer).Cons:
While parsing from a seastar::input_stream is not supported yet, it is nice to
have primitives which allow us to implement it in the future without rewriting
the parsers.