parsers::json
Classes
Array— A JSON array token, templated on its backing storageS:Array<std::vector<Node>> (OwnedArray) owns its elements, Array<std::span<const Node>> (ArrayView) views elements stored elsewhere with no copy.Boolean— A JSONtrue/falsetoken, constructed from its bool: Boolean{true}.Node— The dynamic JSON value: a thin class wrapping a std::variant over the token types (Null, Boolean, Number, owning/viewing String, Array, Object).Null— The JSONnullliteral token.Number— A JSON number token (one numeric type: IEEE-754 double), e.g.Object— A JSON object token, templated on its backing storageS:Object<std::vector<Member>> (OwnedObject) owns its members, Object<std::span<const Member>> (ObjectView) views members in a Parser's pool with no copy.Parser— A reusable parser that owns reusable node/member POOLS.String— A decoded (un-escaped) JSON string token, storing its characters either owned (String<std::string>) or as a zero-copy view (String<std::string_view>), chosen by the storage typeSvia the deduction guides below.
Functions
Read a Node's characters when it is a string (either backing), else an empty view.
value | the node to read. |
the characters when value is a string (either backing), else an empty view.
O(1).
none
Parse text into a SELF-CONTAINED Document (owning containers AND owned strings — every string is copied, not a view), so the result is safe to return, cache, or outlive text.
For the zero-copy, source-viewing form (no string copies), reuse a Parser and call Parser::parse.
Validate is a COMPILE-TIME switch: the default (true) checks bounds/structure and rejects malformed input; parse<false>(...) strips every such check from the binary via if constexpr and does not write *ok — trusted, known-well-formed input only; malformed input is undefined behavior.
text | the JSON source to parse. |
ok | if non-null, set true on success and false on a parse error (written only when Validate is true). |
the self-contained Document (JSON null on error when validating).
O(n) in the input length.
allocates the owned document tree (arrays, objects, and copied strings)
ParsersJsonDom.ParsesEveryScalarKinddump · 2 overloads
Serialize a Document by APPENDING to the caller's buffer — stream into a preallocated/reused std::string rather than allocating a fresh one.
This is the efficient path (push_back/append into one growing buffer); it deliberately avoids std::stringstream, which adds formatting, locale, and virtual-streambuf overhead per write. Reserve out once and reuse it across calls.
value | the document to serialize. |
out | the buffer the JSON text is appended to. |
O(output size).
allocates the O(depth) frame stack; grows out only past its capacity.
Parse text directly into out (a struct with a schema<>, a supported scalar, std::vector, std::array, std::optional, or std::string/std::string_view).
Returns true on success. With Validate=true the input is fully checked (including no trailing junk); with Validate=false every bounds/structure check is compiled out for trusted, well-formed input (malformed input is then undefined behavior, and no success/trailing check is performed — it always returns true).
std::string fields OWN their characters (safe to outlive text); std::string_view fields VIEW text (which must then outlive out) and reject escaped strings.
text | the JSON source to parse. |
out | the value filled in place. |
true on success; false when Validate is true and text is malformed or has trailing junk.
O(n) in the input length.
only the owned std::string fields / vector growth in out, plus a temporary key string when a key is escaped — no DOM, no Node tree.
Build one key->member mapping.
Class | the struct type owning the member. |
Member | the member's value type. |
name | the JSON object key. |
ptr | pointer to the target data member. |
the Field mapping.
O(1) — constexpr aggregate construction.
none.
Bundle fields into a schema.
Fields | the Field types making up the schema. |
fs | the field mappings, in declaration order (cosmetic — matching is by name). |
the ObjectSchema.
O(1) — constexpr tuple construction.
none.
String · 3 overloads
Deduction guides — route each argument to the right storage.
A const char* and a std::string_view become VIEWS (never a std::string); an rvalue std::string is OWNED. These user-defined guides are preferred over the implicit one, so String{"lit"} deduces String<std::string_view>, not String<const char*>.
O(1) — deduction is compile-time; the chosen constructor moves or views.
none.
Decode the raw (escaped) inner bytes of a JSON string (scan.hpp's detail::decode_escapes).
O(|raw|).
output growth (reserved once up front).
Consume an exact literal like "true" if present, else leave the cursor put (detail::match).
Scan a quoted string to its raw inner bytes + had-escapes flag (detail::scan_string).
O(|string|) — SIMD, 32 bytes per step.
none — the raw bytes are a view.
Advance the cursor past JSON whitespace (detail::skip_ws over the SIMD skip).
Constants & variables
JSON schema for Options, synthesized by purrc from the struct's fields — powers parsers.json.read into this type.
JSON schema for Response, synthesized by purrc from the struct's fields — powers parsers.json.read into this type.
