|
pjson 1.0.0
A small, owning JSON value for C++11
|
Owning, mutable JSON value with deep-copy semantics. More...
#include <pjson.h>
Classes | |
| struct | Allocator |
| Runtime allocator for persistent DOM storage. The allocator is non-owning and must outlive every pjson value that refers to it. Allocation covers pjson child/root nodes plus the std::string, array, and object wrapper objects. Storage used internally by those standard-library objects and transient parser/algorithm scratch space continues to use the standard allocator. More... | |
| struct | ParseError |
Filled in by the error-reporting parse() overloads. ok is true when parsing succeeded; otherwise offset is the zero-based byte position, line is one-based, column is a one-based byte column, and message describes the first failure. Reporting parse APIs reset all fields on entry and leave this success state after a successful parse. More... | |
| struct | ParseOptions |
| Bounds how much work a parse may do. Parsing always enforces RFC 8259 conformance and rejects: More... | |
| struct | PatchError |
| Structured JSON Patch (RFC 6902) / Merge Patch (RFC 7396) failure. Patch application is atomic: failure leaves the target unchanged. Reporting patch APIs reset all fields on entry and on success. More... | |
| struct | PatchOptions |
| Bounds transactional patch amplification. Zero selects the documented built-in ceiling rather than disabling a safety limit. Clone bytes include node storage plus string and object-key payload bytes. More... | |
| struct | PointerError |
Structured JSON Pointer (RFC 6901) lookup failure. tokenIndex is zero-based and token is the decoded token that could not be resolved (or the source token when its escape sequence is invalid). std::string reporting overloads reset all fields on entry. A C-string overload can report allocation failure before copying the pointer text. More... | |
| struct | SaxHandler |
| Event sink for non-owning SAX parsing. Return false from any callback to cancel parsing; public parseSax* APIs return false for cancellation or thrown exceptions and populate ParseError when one is supplied. More... | |
| struct | SchemaError |
One schema-validation failure: path is a JSON Pointer to the offending node (e.g. "/address/zip", "" for the document root) and message explains what was wrong. More... | |
| struct | SchemaOptions |
| Bounds schema regular-expression work. By default only a conservative, non-ambiguous ECMAScript subset is accepted and both pattern/subject sizes are capped, preventing catastrophic std::regex backtracking. trustedRegex() restores unrestricted ECMAScript regex behavior for schemas and input controlled by the application. More... | |
| struct | SerializeOptions |
| Controls JSON serialization. The default produces the same compact, ascending-key output as toString()/write() without options. Pretty output places each array element/object member on its own line. Only space and tab are valid indentation characters; any other value is treated as a space so serialization always remains valid JSON. More... | |
| class | StringView |
| Minimal C++11-compatible, non-owning view of a JSON string. A view aliases bytes owned by this pjson node and is valid only while that node remains alive and unchanged. Assignment, reset, swap, move, destruction, erasing the node, or replacing/resetting an ancestor invalidates it. Strings may contain embedded NUL bytes; use size() rather than strlen(). More... | |
| struct | ValueDeleter |
| Stateless ownership for allocator-created nodes. Provenance is read from the node itself, so moving this pointer never transfers or owns the Allocator object. More... | |
Public Types | |
| enum | jsonType : int64_t { jsonNull = 0 , jsonString , jsonNumberInt , jsonNumberDouble , jsonBoolean , jsonArray , jsonObject } |
| JSON value kind. Numbers are stored in one of two representations: whole numbers as a 64-bit signed integer (jsonNumberInt) and everything else as a double (jsonNumberDouble). More... | |
| typedef std::unique_ptr< pjson, ValueDeleter > | unique_ptr |
Public API member unique_ptr; see the API overview for its contract. | |
Public Member Functions | |
| pjson () | |
Public API member pjson; see the API overview for its contract. / Constructs null bound to borrowed aAlloc, which must outlive this tree. | |
| pjson (Allocator &aAlloc) noexcept | |
Public API member pjson; see the API overview for its contract. / Destroys this value and its complete owned subtree. | |
| ~pjson () | |
Public API member ~pjson; see the API overview for its contract. / Deep-copies aFrom using aFrom's borrowed allocator. | |
| pjson (const pjson &aFrom) | |
Public API member pjson; see the API overview for its contract. / Deep-copies aFrom into borrowed aAlloc. | |
| pjson (const pjson &aFrom, Allocator &aAlloc) | |
Public API member pjson; see the API overview for its contract. / Transfers aFrom's storage and allocator in O(1), leaving aFrom null. | |
| pjson (pjson &&aFrom) noexcept | |
Public API member pjson; see the API overview for its contract. / Transfers in O(1) when allocators match; otherwise deep-copies then clears aFrom. | |
| pjson (pjson &&aFrom, Allocator &aAlloc) | |
Public API member pjson; see the API overview for its contract. / Deep-copies aFrom while preserving this value's allocator. | |
| pjson & | operator= (const pjson &aFrom) |
Public API member operator=; see the API overview for its contract. / Moves aFrom while preserving this allocator; cross-allocator moves may allocate. | |
| pjson & | operator= (pjson &&aFrom) |
Public API member operator=; see the API overview for its contract. / Deep-copies aFrom while preserving this value's allocator. | |
| void | copyFrom (const pjson &aFrom) |
Public API member copyFrom; see the API overview for its contract. / Destroys the current contents and becomes null. | |
| void | reset () |
Public API member reset; see the API overview for its contract. / Replaces the value with the empty/default value of a valid jsonType. | |
| void | resetTo (jsonType aeType) |
Public API member resetTo; see the API overview for its contract. / Calls resetTo() only when the type differs, otherwise preserving contents. | |
| void | resetIfNeeded (jsonType aeType) |
Public API member resetIfNeeded; see the API overview for its contract. Same-allocator swap is O(1). A cross-allocator swap is rejected as a safe no-op; use canSwap() to test before requesting it. / Exchanges contents when allocators match; otherwise does nothing. | |
| void | swap (pjson &aOther) noexcept |
Public API member swap; see the API overview for its contract. / Returns the borrowed allocator bound to this value. | |
| Allocator & | getAllocator () const noexcept |
Public API member getAllocator; see the API overview for its contract. / Returns whether swap(aOther) can exchange contents. | |
| bool | canSwap (const pjson &aOther) const noexcept |
Public API member canSwap; see the API overview for its contract. | |
| std::string | toString () const |
| Non-finite stored doubles serialize as JSON null. Invalid UTF-8 in a string value or object key is a serialization failure: toString() throws, while write() sets failbit (and may propagate stream exceptions). toString() may also throw for allocation or length failure. / Returns compact JSON using the default serialization options. | |
| std::string | toString (const SerializeOptions &aOpts) const |
Public API member toString; see the API overview for its contract. / Writes compact JSON to aOut using the default serialization options. | |
| void | write (std::ostream &aOut) const |
Public API member write; see the API overview for its contract. / Writes JSON configured by aOpts to aOut. | |
| void | write (std::ostream &aOut, const SerializeOptions &aOpts) const |
Public API member write; see the API overview for its contract. | |
| jsonType | getType () const |
Public API member getType; see the API overview for its contract. / Returns whether this node is null. | |
| bool | isNull () const |
Public API member isNull; see the API overview for its contract. / Returns whether this node stores a string. | |
| bool | isString () const |
Public API member isString; see the API overview for its contract. / Returns whether this node stores either numeric representation. | |
| bool | isNumber () const |
Public API member isNumber; see the API overview for its contract. / Returns whether this node stores an integer representation. | |
| bool | isInt () const |
Public API member isInt; see the API overview for its contract. / Returns whether this node stores a floating-point representation. | |
| bool | isDouble () const |
Public API member isDouble; see the API overview for its contract. / Returns whether this node stores a boolean. | |
| bool | isBool () const |
Public API member isBool; see the API overview for its contract. / Returns whether this node stores an array. | |
| bool | isArray () const |
Public API member isArray; see the API overview for its contract. / Returns whether this node stores an object. | |
| bool | isObject () const |
Public API member isObject; see the API overview for its contract. | |
| bool | tryGet (int64_t &aResult) const noexcept |
| Strict typed access to this node. On a type mismatch, returns false and leaves aResult unchanged. Integers may widen to double; no other coercions are performed. StringView avoids a string copy. / Extracts an integer only when this node stores jsonNumberInt. | |
| bool | tryGet (double &aResult) const noexcept |
Public API member tryGet; see the API overview for its contract. / Extracts a boolean only when this node stores jsonBoolean. | |
| bool | tryGet (bool &aResult) const noexcept |
Public API member tryGet; see the API overview for its contract. / Copies a string only when this node stores jsonString. | |
| bool | tryGet (std::string &aResult) const |
Public API member tryGet; see the API overview for its contract. / Borrows a string view only when this node stores jsonString. | |
| bool | tryGet (StringView &aResult) const noexcept |
Public API member tryGet; see the API overview for its contract. | |
| size_t | size () const |
Public API member size; see the API overview for its contract. / Returns whether size() is zero; consequently all scalar values are empty. | |
| bool | empty () const |
Public API member empty; see the API overview for its contract. / Empties a container without changing its type, or resets a scalar to null. | |
| void | clear () |
Public API member clear; see the API overview for its contract. | |
| std::vector< std::string > | keys () const |
Public API member keys; see the API overview for its contract. | |
| bool | hasKey (const std::string &aKey) const |
Public API member hasKey; see the API overview for its contract. / Returns whether this object contains non-null aKey; null returns false. | |
| bool | hasKey (const char *aKey) const |
Public API member hasKey; see the API overview for its contract. / Returns whether this array contains aIndex; negative indexes count from the end. | |
| bool | hasIndex (int aIndex) const noexcept |
Public API member hasIndex; see the API overview for its contract. | |
| pjson * | find (const std::string &aKey) |
| Returns a pointer to the child stored under aKey, or nullptr when this is not a map or the key is absent. Unlike operator[], this never creates or mutates anything. / Returns the borrowed child at aKey, or null when absent or not an object. | |
| pjson * | find (const char *aKey) |
Public API member find; see the API overview for its contract. / Returns the read-only borrowed child at aKey, or null on failure. | |
| const pjson * | find (const std::string &aKey) const |
Public API member find; see the API overview for its contract. / Returns the read-only borrowed child at non-null aKey, or null on failure. | |
| const pjson * | find (const char *aKey) const |
Public API member find; see the API overview for its contract. | |
| pjson * | find (int aIndex) noexcept |
| Non-vivifying array lookup. Negative indexes count from the end (-1 is the last element); indexes outside the array return nullptr. These overloads never change this node or its size. / Returns the borrowed array child at aIndex, or null on failure. | |
| const pjson * | find (int aIndex) const noexcept |
Public API member find; see the API overview for its contract. | |
| pjson * | findPointer (const std::string &aPointer) |
Public API member findPointer; see the API overview for its contract. / Resolves aPointer and returns the read-only borrowed target, or null. | |
| const pjson * | findPointer (const std::string &aPointer) const |
Public API member findPointer; see the API overview for its contract. / Resolves aPointer and reports lookup failure in aError. | |
| pjson * | findPointer (const std::string &aPointer, PointerError &aError) |
Public API member findPointer; see the API overview for its contract. / Resolves aPointer read-only and reports lookup failure in aError. | |
| const pjson * | findPointer (const std::string &aPointer, PointerError &aError) const |
Public API member findPointer; see the API overview for its contract. / Resolves a non-null pointer string; null returns failure. | |
| pjson * | findPointer (const char *aPointer) |
Public API member findPointer; see the API overview for its contract. / Resolves a non-null pointer string read-only; null returns failure. | |
| const pjson * | findPointer (const char *aPointer) const |
Public API member findPointer; see the API overview for its contract. / Resolves a non-null pointer string and reports failure in aError. | |
| pjson * | findPointer (const char *aPointer, PointerError &aError) |
Public API member findPointer; see the API overview for its contract. / Resolves a non-null pointer string read-only and reports failure in aError. | |
| const pjson * | findPointer (const char *aPointer, PointerError &aError) const |
Public API member findPointer; see the API overview for its contract. | |
| bool | tryGet (const std::string &aKey, int64_t &aResult) const |
| Strict typed child access layered on find() and node-level tryGet(). Missing/null keys, invalid indexes, and type mismatches leave aResult unchanged. Negative indexes count from the end. / Extracts the integer child at aKey without mutating this object. | |
| bool | tryGet (const std::string &aKey, double &aResult) const |
Public API member tryGet; see the API overview for its contract. / Extracts the boolean child at aKey. | |
| bool | tryGet (const std::string &aKey, bool &aResult) const |
Public API member tryGet; see the API overview for its contract. / Copies the string child at aKey. | |
| bool | tryGet (const std::string &aKey, std::string &aResult) const |
Public API member tryGet; see the API overview for its contract. / Borrows a view of the string child at aKey. | |
| bool | tryGet (const std::string &aKey, StringView &aResult) const |
Public API member tryGet; see the API overview for its contract. | |
| bool | tryGet (const char *aKey, int64_t &aResult) const |
Public API member tryGet; see the API overview for its contract. / Extracts the numeric child at non-null aKey as a double. | |
| bool | tryGet (const char *aKey, double &aResult) const |
Public API member tryGet; see the API overview for its contract. / Extracts the boolean child at non-null aKey. | |
| bool | tryGet (const char *aKey, bool &aResult) const |
Public API member tryGet; see the API overview for its contract. / Copies the string child at non-null aKey. | |
| bool | tryGet (const char *aKey, std::string &aResult) const |
Public API member tryGet; see the API overview for its contract. / Borrows a view of the string child at non-null aKey. | |
| bool | tryGet (const char *aKey, StringView &aResult) const |
Public API member tryGet; see the API overview for its contract. | |
| bool | tryGet (int aIndex, int64_t &aResult) const noexcept |
Public API member tryGet; see the API overview for its contract. / Extracts the numeric array child at aIndex as a double. | |
| bool | tryGet (int aIndex, double &aResult) const noexcept |
Public API member tryGet; see the API overview for its contract. / Extracts the boolean array child at aIndex. | |
| bool | tryGet (int aIndex, bool &aResult) const noexcept |
Public API member tryGet; see the API overview for its contract. / Copies the string array child at aIndex. | |
| bool | tryGet (int aIndex, std::string &aResult) const |
Public API member tryGet; see the API overview for its contract. / Borrows a view of the string array child at aIndex. | |
| bool | tryGet (int aIndex, StringView &aResult) const noexcept |
Public API member tryGet; see the API overview for its contract. | |
| pjson & | operator[] (const std::string &aString) |
| operator[] is a direct builder API. A key access changes a non-object into an object and creates a missing null child. An index access changes a non-array into an array; negative indexes count from the end and clamp before the beginning to zero, while indexes past the end grow the array with null children. A single access that would create more than one million children throws std::length_error before mutation. Use find()/tryGet() for reads. / Returns or creates the child at aString. | |
| pjson & | operator[] (const char *aSkey) |
Public API member operator[]; see the API overview for its contract. / Returns or creates the child at index under the auto-growth rules above. | |
| pjson & | operator[] (int index) |
Public API member operator[]; see the API overview for its contract. | |
| pjson & | operator= (const std::string &aString) |
| Assign a scalar value, replacing whatever this node was. Numbers are stored as int64_t (integers) or double (floating point). / Replaces this value with a copy of aString. | |
| pjson & | operator= (const char *aCString) |
Public API member operator=; see the API overview for its contract. / Replaces this value with aBool. | |
| pjson & | operator= (const bool aBool) |
Public API member operator=; see the API overview for its contract. / Replaces this value with aInt. | |
| pjson & | operator= (const int64_t aInt) |
Public API member operator=; see the API overview for its contract. / Replaces this value with aDouble; non-finite values serialize as null. | |
| pjson & | operator= (const double aDouble) |
Public API member operator=; see the API overview for its contract. | |
| pjson & | operator= (const std::vector< std::string > &aValueArray) |
| Vector assignment atomically replaces this node with an array of copied children allocated through this node's allocator. / Replaces this value with a copied string array. | |
| pjson & | operator= (const std::vector< bool > &aValueArray) |
Public API member operator=; see the API overview for its contract. / Replaces this value with a copied integer array. | |
| pjson & | operator= (const std::vector< int64_t > &aValueArray) |
Public API member operator=; see the API overview for its contract. / Replaces this value with a copied double array. | |
| pjson & | operator= (const std::vector< double > &aValueArray) |
Public API member operator=; see the API overview for its contract. | |
| pjson & | operator+= (const std::string &aValue) |
| Scalar append adds one copied child. If this node is not already an array, its previous value is discarded rather than retained. / Appends a copy of aValue as a string child. | |
| pjson & | operator+= (const char *aValue) |
Public API member operator+=; see the API overview for its contract. / Appends aValue as a boolean child. | |
| pjson & | operator+= (const bool aValue) |
Public API member operator+=; see the API overview for its contract. / Appends aValue as an integer child. | |
| pjson & | operator+= (const int64_t aValue) |
Public API member operator+=; see the API overview for its contract. / Appends aValue as a double child. | |
| pjson & | operator+= (const double aValue) |
Public API member operator+=; see the API overview for its contract. | |
| pjson & | operator+= (const std::vector< std::string > &aValueArray) |
| Vector append copies every element. A non-array's prior value is discarded; even an empty vector promotes a non-array to an empty array. / Appends every string in aValueArray. | |
| pjson & | operator+= (const std::vector< bool > &aValueArray) |
Public API member operator+=; see the API overview for its contract. / Appends every integer in aValueArray. | |
| pjson & | operator+= (const std::vector< int64_t > &aValueArray) |
Public API member operator+=; see the API overview for its contract. / Appends every double in aValueArray. | |
| pjson & | operator+= (const std::vector< double > &aValueArray) |
Public API member operator+=; see the API overview for its contract. | |
| bool | erase (const std::string &aKey) |
| Remove and free the child under a map key / at an array index. Array indexes are zero-based and erasure shifts later elements left. / Erases aKey and returns whether an object member was removed. | |
| bool | erase (const char *aKey) |
Public API member erase; see the API overview for its contract. / Erases aIndex and returns whether an array element was removed. | |
| bool | erase (size_t aIndex) |
Public API member erase; see the API overview for its contract. | |
| bool | applyPatch (const pjson &aPatch, const PatchOptions &aOpts=PatchOptions()) noexcept |
| Applies all RFC 6902 operations to a scratch document and commits only if every operation succeeds. RFC 7396 Merge Patch is likewise atomic and uses an iterative traversal for deeply nested objects. These bool-returning boundaries convert allocation and internal exceptions into PatchError instead of allowing them to escape. Patch input is borrowed and unchanged; successful commit invalidates prior views into the target. Overloads without aError discard diagnostics. / Atomically applies an RFC 6902 patch document. | |
| bool | applyPatch (const pjson &aPatch, PatchError &aError, const PatchOptions &aOpts=PatchOptions()) noexcept |
Public API member PatchOptions; see the API overview for its contract. / Atomically applies an RFC 7396 Merge Patch document. | |
| bool | applyMergePatch (const pjson &aPatch, const PatchOptions &aOpts=PatchOptions()) noexcept |
Public API member PatchOptions; see the API overview for its contract. / Atomically applies RFC 7396 and reports failure details in aError. | |
| bool | applyMergePatch (const pjson &aPatch, PatchError &aError, const PatchOptions &aOpts=PatchOptions()) noexcept |
Public API member PatchOptions; see the API overview for its contract. | |
| bool | operator== (const pjson &aOther) const |
| Integer and floating nodes compare equal when numerically equal (e.g. 1 == 1.0). Arrays compare element-wise in order; objects compare by key/value regardless of insertion order. / Returns whether this value and aOther are structurally equal. | |
| bool | operator!= (const pjson &aOther) const |
Public API member operator!=; see the API overview for its contract. | |
| bool | validate (const pjson &aSchema, const SchemaOptions &aOpts=SchemaOptions()) const noexcept |
| Validates this value against a schema that is itself a pjson object, using the documented JSON Schema subset; this is not a complete draft implementation. Returns true when the value conforms. Never throws. The second form appends reported keyword failures rather than stopping at the first. Errors inside non-selected anyOf/oneOf/not branches are intentionally suppressed, and a resource-budget failure can stop further validation. | |
| bool | validate (const pjson &aSchema, std::vector< SchemaError > &aErrors, const SchemaOptions &aOpts=SchemaOptions()) const noexcept |
Public API member SchemaOptions; see the API overview for its contract. | |
Static Public Member Functions | |
| static const char * | getVersion () |
Public API member getVersion; see the API overview for its contract. | |
| static pjson::unique_ptr | parse (const std::string &aStr, const ParseOptions &aOpts=ParseOptions()) |
| Each parse accepts exactly one JSON value followed only by whitespace. In-memory parse failures return an empty pointer; diagnostic overloads reset aError and describe the first failure. A byte span may contain embedded NUL bytes, but a null aSrc is always an error. / Parses aStr into an owning tree using the default allocator. | |
| static pjson::unique_ptr | parse (const char *aSrc, size_t aSize, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / Parses aStr and reports the first failure in aError. | |
| static pjson::unique_ptr | parse (const std::string &aStr, ParseError &aError, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / Parses the aSize-byte span and reports the first failure in aError. | |
| static pjson::unique_ptr | parse (const char *aSrc, size_t aSize, ParseError &aError, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. | |
| static pjson::unique_ptr | parseStream (std::istream &aIn, const ParseOptions &aOpts=ParseOptions()) |
| parseStream() buffers the document in chunks while enforcing maxInputBytes. Stream or temporary-buffer exceptions may propagate. / Buffers and parses one document from aIn using the default allocator. | |
| static pjson::unique_ptr | parseStream (std::istream &aIn, ParseError &aError, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. | |
| static unique_ptr | parse (const std::string &aStr, Allocator &aAlloc, const ParseOptions &aOpts=ParseOptions()) |
| Allocator-aware DOM parsing routes root/child nodes and string/array/ object wrapper objects through borrowed aAlloc. Standard-container backing buffers still use their standard allocators, as described by Allocator above. aAlloc must outlive the returned tree. / Parses aStr with allocator-backed nodes and wrapper objects. | |
| static unique_ptr | parse (const char *aSrc, size_t aSize, Allocator &aAlloc, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / Parses aStr with aAlloc and reports the first failure in aError. | |
| static unique_ptr | parse (const std::string &aStr, ParseError &aError, Allocator &aAlloc, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / Parses a byte span with aAlloc and reports the first failure in aError. | |
| static unique_ptr | parse (const char *aSrc, size_t aSize, ParseError &aError, Allocator &aAlloc, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / Buffers aIn, then parses with allocator-backed nodes and wrappers. | |
| static unique_ptr | parseStream (std::istream &aIn, Allocator &aAlloc, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / Buffers and parses aIn with aAlloc, reporting ordinary failures in aError. | |
| static unique_ptr | parseStream (std::istream &aIn, ParseError &aError, Allocator &aAlloc, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. | |
| static bool | parseSax (const std::string &aStr, SaxHandler &aHandler, const ParseOptions &aOpts=ParseOptions()) |
| SAX parsing retains neither aHandler nor callback arguments. It returns false for invalid input, cancellation, stream failure, or a handler exception; callbacks already delivered before failure are not undone. / Parses aStr and emits its events to aHandler without building a DOM. | |
| static bool | parseSax (const char *aSrc, size_t aSize, SaxHandler &aHandler, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / SAX-parses aStr and reports failure or cancellation in aError. | |
| static bool | parseSax (const std::string &aStr, SaxHandler &aHandler, ParseError &aError, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / SAX-parses a byte span and reports failure or cancellation in aError. | |
| static bool | parseSax (const char *aSrc, size_t aSize, SaxHandler &aHandler, ParseError &aError, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. True streaming SAX parse: reads the istream incrementally and never buffers the full document in memory. / Incrementally parses aIn and emits events to aHandler. | |
| static bool | parseSaxStream (std::istream &aIn, SaxHandler &aHandler, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. / Incrementally SAX-parses aIn and reports failure or cancellation in aError. | |
| static bool | parseSaxStream (std::istream &aIn, SaxHandler &aHandler, ParseError &aError, const ParseOptions &aOpts=ParseOptions()) |
Public API member ParseOptions; see the API overview for its contract. | |
| static std::string | escapePointerToken (const std::string &aToken) |
| RFC 6901 lookup. The empty pointer addresses this value; every non-empty pointer must begin with '/'. Lookups are iterative and never create missing nodes. The '-' token is not a lookup index. / Escapes one decoded reference token for inclusion in a JSON Pointer. | |
Owning, mutable JSON value with deep-copy semantics.
An owning, mutable value that represents every JSON type.
Child pointers and string views exposed by lookup/access APIs are borrowed from the owning tree. They become invalid when the child or an ancestor is destroyed, replaced, reset, erased, moved, swapped, cleared, or successfully patched. Unless an operation is noexcept or explicitly reports failures, allocation and standard-library exceptions may escape.
A pjson owns its complete subtree. Copies are deep, and pointers returned by find() or findPointer(), along with string views returned by tryGet(), remain borrowed from their owning tree. In-memory parsing and validation report data-domain failures through return values and error objects; exception-enabled input streams can still propagate stream exceptions while parseStream() buffers input.
Every value is bound to a runtime allocator. Default construction uses the built-in allocator; allocator-aware construction and parsing use a borrowed pjson::Allocator that must outlive the complete tree. Copy and move assignment preserve the destination allocator. Storage transfer and swap are O(1) only between values with the same allocator; use canSwap() when allocator provenance may differ. Every DOM parse() and parseStream() overload returns pjson::unique_ptr so pjson::ValueDeleter can release the root through its originating allocator. An empty pointer reports a parse failure.
operator[] is the auto-vivifying builder API. For observation without mutation, use find(), findPointer(), hasKey(), hasIndex(), or tryGet(). tryGet() requires the requested stored type and leaves its output unchanged on failure; only an integer-to-double widening conversion is permitted. Containers expose query and child-lookup operations rather than their raw storage types.
getType() distinguishes jsonNumberInt from jsonNumberDouble and reports objects as jsonObject. Numeric assignment and append overloads accept int64_t or double. Configure serialization through SerializeOptions; the compact toString() and write() overloads take no formatting boolean, and SerializeOptions::maxOutputBytes bounds generated output. PatchOptions bounds transactional JSON Patch and Merge Patch amplification. Invalid UTF-8 and logical output-size failures are detected before write() emits bytes.
| typedef std::unique_ptr<pjson, ValueDeleter> ByteDance::pjson::unique_ptr |
JSON value kind. Numbers are stored in one of two representations: whole numbers as a 64-bit signed integer (jsonNumberInt) and everything else as a double (jsonNumberDouble).
| ByteDance::pjson::pjson | ( | ) |
Public API member pjson; see the API overview for its contract. / Constructs null bound to borrowed aAlloc, which must outlive this tree.
|
explicitnoexcept |
Public API member pjson; see the API overview for its contract. / Destroys this value and its complete owned subtree.
| ByteDance::pjson::~pjson | ( | ) |
Public API member ~pjson; see the API overview for its contract. / Deep-copies aFrom using aFrom's borrowed allocator.
Public API member pjson; see the API overview for its contract. / Deep-copies aFrom into borrowed aAlloc.
Public API member pjson; see the API overview for its contract. / Transfers aFrom's storage and allocator in O(1), leaving aFrom null.
|
noexcept |
Public API member pjson; see the API overview for its contract. / Transfers in O(1) when allocators match; otherwise deep-copies then clears aFrom.
Public API member pjson; see the API overview for its contract. / Deep-copies aFrom while preserving this value's allocator.
|
noexcept |
Public API member PatchOptions; see the API overview for its contract. / Atomically applies RFC 7396 and reports failure details in aError.
|
noexcept |
Public API member PatchOptions; see the API overview for its contract.
|
noexcept |
Applies all RFC 6902 operations to a scratch document and commits only if every operation succeeds. RFC 7396 Merge Patch is likewise atomic and uses an iterative traversal for deeply nested objects. These bool-returning boundaries convert allocation and internal exceptions into PatchError instead of allowing them to escape. Patch input is borrowed and unchanged; successful commit invalidates prior views into the target. Overloads without aError discard diagnostics. / Atomically applies an RFC 6902 patch document.
Public API member PatchOptions; see the API overview for its contract. / Atomically applies RFC 6902 and reports failure details in aError.
|
noexcept |
Public API member PatchOptions; see the API overview for its contract. / Atomically applies an RFC 7396 Merge Patch document.
Public API member canSwap; see the API overview for its contract.
| void ByteDance::pjson::clear | ( | ) |
Public API member clear; see the API overview for its contract.
Public API member copyFrom; see the API overview for its contract. / Destroys the current contents and becomes null.
| bool ByteDance::pjson::empty | ( | ) | const |
Public API member empty; see the API overview for its contract. / Empties a container without changing its type, or resets a scalar to null.
Public API member erase; see the API overview for its contract. / Erases aIndex and returns whether an array element was removed.
Remove and free the child under a map key / at an array index. Array indexes are zero-based and erasure shifts later elements left. / Erases aKey and returns whether an object member was removed.
Public API member erase; see the API overview for its contract. / Erases non-null aKey; null or a non-object returns false.
Public API member erase; see the API overview for its contract.
RFC 6901 lookup. The empty pointer addresses this value; every non-empty pointer must begin with '/'. Lookups are iterative and never create missing nodes. The '-' token is not a lookup index. / Escapes one decoded reference token for inclusion in a JSON Pointer.
Public API member escapePointerToken; see the API overview for its contract. / Resolves aPointer and returns the borrowed target, or null on failure.
Public API member find; see the API overview for its contract. / Returns the read-only borrowed child at aKey, or null on failure.
Public API member find; see the API overview for its contract.
Returns a pointer to the child stored under aKey, or nullptr when this is not a map or the key is absent. Unlike operator[], this never creates or mutates anything. / Returns the borrowed child at aKey, or null when absent or not an object.
Public API member find; see the API overview for its contract. / Returns the borrowed child at non-null aKey, or null on failure.
Public API member find; see the API overview for its contract. / Returns the read-only borrowed child at non-null aKey, or null on failure.
Public API member find; see the API overview for its contract.
Non-vivifying array lookup. Negative indexes count from the end (-1 is the last element); indexes outside the array return nullptr. These overloads never change this node or its size. / Returns the borrowed array child at aIndex, or null on failure.
Public API member find; see the API overview for its contract. / Returns the read-only borrowed array child at aIndex, or null on failure.
Public API member findPointer; see the API overview for its contract. / Resolves a non-null pointer string read-only; null returns failure.
Public API member findPointer; see the API overview for its contract. / Resolves a non-null pointer string and reports failure in aError.
| pjson * ByteDance::pjson::findPointer | ( | const char * | aPointer, |
| PointerError & | aError | ||
| ) |
Public API member findPointer; see the API overview for its contract. / Resolves a non-null pointer string read-only and reports failure in aError.
| const pjson * ByteDance::pjson::findPointer | ( | const char * | aPointer, |
| PointerError & | aError | ||
| ) | const |
Public API member findPointer; see the API overview for its contract.
Public API member findPointer; see the API overview for its contract. / Resolves aPointer and returns the read-only borrowed target, or null.
Public API member findPointer; see the API overview for its contract. / Resolves aPointer and reports lookup failure in aError.
| pjson * ByteDance::pjson::findPointer | ( | const std::string & | aPointer, |
| PointerError & | aError | ||
| ) |
Public API member findPointer; see the API overview for its contract. / Resolves aPointer read-only and reports lookup failure in aError.
| const pjson * ByteDance::pjson::findPointer | ( | const std::string & | aPointer, |
| PointerError & | aError | ||
| ) | const |
Public API member findPointer; see the API overview for its contract. / Resolves a non-null pointer string; null returns failure.
|
noexcept |
Public API member getAllocator; see the API overview for its contract. / Returns whether swap(aOther) can exchange contents.
| jsonType ByteDance::pjson::getType | ( | ) | const |
Public API member getType; see the API overview for its contract. / Returns whether this node is null.
Public API member getVersion; see the API overview for its contract.
Public API member hasIndex; see the API overview for its contract.
Public API member hasKey; see the API overview for its contract. / Returns whether this array contains aIndex; negative indexes count from the end.
Public API member hasKey; see the API overview for its contract. / Returns whether this object contains non-null aKey; null returns false.
| bool ByteDance::pjson::isArray | ( | ) | const |
Public API member isArray; see the API overview for its contract. / Returns whether this node stores an object.
| bool ByteDance::pjson::isBool | ( | ) | const |
Public API member isBool; see the API overview for its contract. / Returns whether this node stores an array.
| bool ByteDance::pjson::isDouble | ( | ) | const |
Public API member isDouble; see the API overview for its contract. / Returns whether this node stores a boolean.
| bool ByteDance::pjson::isInt | ( | ) | const |
Public API member isInt; see the API overview for its contract. / Returns whether this node stores a floating-point representation.
| bool ByteDance::pjson::isNull | ( | ) | const |
Public API member isNull; see the API overview for its contract. / Returns whether this node stores a string.
| bool ByteDance::pjson::isNumber | ( | ) | const |
Public API member isNumber; see the API overview for its contract. / Returns whether this node stores an integer representation.
| bool ByteDance::pjson::isObject | ( | ) | const |
Public API member isObject; see the API overview for its contract.
| bool ByteDance::pjson::isString | ( | ) | const |
Public API member isString; see the API overview for its contract. / Returns whether this node stores either numeric representation.
| std::vector< std::string > ByteDance::pjson::keys | ( | ) | const |
Public API member keys; see the API overview for its contract.
| bool ByteDance::pjson::operator!= | ( | const pjson & | aOther | ) | const |
Public API member operator!=; see the API overview for its contract.
| pjson & ByteDance::pjson::operator+= | ( | const bool | aValue | ) |
Public API member operator+=; see the API overview for its contract. / Appends aValue as an integer child.
| pjson & ByteDance::pjson::operator+= | ( | const char * | aValue | ) |
Public API member operator+=; see the API overview for its contract. / Appends aValue as a boolean child.
| pjson & ByteDance::pjson::operator+= | ( | const double | aValue | ) |
Public API member operator+=; see the API overview for its contract.
| pjson & ByteDance::pjson::operator+= | ( | const int64_t | aValue | ) |
Public API member operator+=; see the API overview for its contract. / Appends aValue as a double child.
| pjson & ByteDance::pjson::operator+= | ( | const std::string & | aValue | ) |
Scalar append adds one copied child. If this node is not already an array, its previous value is discarded rather than retained. / Appends a copy of aValue as a string child.
Public API member operator+=; see the API overview for its contract. / Appends aValue as a string child; throws std::invalid_argument for null.
| pjson & ByteDance::pjson::operator+= | ( | const std::vector< bool > & | aValueArray | ) |
Public API member operator+=; see the API overview for its contract. / Appends every integer in aValueArray.
| pjson & ByteDance::pjson::operator+= | ( | const std::vector< double > & | aValueArray | ) |
Public API member operator+=; see the API overview for its contract.
| pjson & ByteDance::pjson::operator+= | ( | const std::vector< int64_t > & | aValueArray | ) |
Public API member operator+=; see the API overview for its contract. / Appends every double in aValueArray.
| pjson & ByteDance::pjson::operator+= | ( | const std::vector< std::string > & | aValueArray | ) |
Vector append copies every element. A non-array's prior value is discarded; even an empty vector promotes a non-array to an empty array. / Appends every string in aValueArray.
Public API member operator+=; see the API overview for its contract. / Appends every boolean in aValueArray.
| pjson & ByteDance::pjson::operator= | ( | const bool | aBool | ) |
Public API member operator=; see the API overview for its contract. / Replaces this value with aInt.
| pjson & ByteDance::pjson::operator= | ( | const char * | aCString | ) |
Public API member operator=; see the API overview for its contract. / Replaces this value with aBool.
| pjson & ByteDance::pjson::operator= | ( | const double | aDouble | ) |
Public API member operator=; see the API overview for its contract.
| pjson & ByteDance::pjson::operator= | ( | const int64_t | aInt | ) |
Public API member operator=; see the API overview for its contract. / Replaces this value with aDouble; non-finite values serialize as null.
| pjson & ByteDance::pjson::operator= | ( | const pjson & | aFrom | ) |
Public API member operator=; see the API overview for its contract. / Moves aFrom while preserving this allocator; cross-allocator moves may allocate.
| pjson & ByteDance::pjson::operator= | ( | const std::string & | aString | ) |
Assign a scalar value, replacing whatever this node was. Numbers are stored as int64_t (integers) or double (floating point). / Replaces this value with a copy of aString.
Public API member operator=; see the API overview for its contract. / Replaces this value with aCString; throws std::invalid_argument for null.
| pjson & ByteDance::pjson::operator= | ( | const std::vector< bool > & | aValueArray | ) |
Public API member operator=; see the API overview for its contract. / Replaces this value with a copied integer array.
| pjson & ByteDance::pjson::operator= | ( | const std::vector< double > & | aValueArray | ) |
Public API member operator=; see the API overview for its contract.
| pjson & ByteDance::pjson::operator= | ( | const std::vector< int64_t > & | aValueArray | ) |
Public API member operator=; see the API overview for its contract. / Replaces this value with a copied double array.
| pjson & ByteDance::pjson::operator= | ( | const std::vector< std::string > & | aValueArray | ) |
Vector assignment atomically replaces this node with an array of copied children allocated through this node's allocator. / Replaces this value with a copied string array.
Public API member operator=; see the API overview for its contract. / Replaces this value with a copied boolean array.
| pjson & ByteDance::pjson::operator= | ( | pjson && | aFrom | ) |
Public API member operator=; see the API overview for its contract. / Deep-copies aFrom while preserving this value's allocator.
| bool ByteDance::pjson::operator== | ( | const pjson & | aOther | ) | const |
Integer and floating nodes compare equal when numerically equal (e.g. 1 == 1.0). Arrays compare element-wise in order; objects compare by key/value regardless of insertion order. / Returns whether this value and aOther are structurally equal.
Public API member operator==; see the API overview for its contract. / Returns the negation of operator==.
| pjson & ByteDance::pjson::operator[] | ( | const char * | aSkey | ) |
Public API member operator[]; see the API overview for its contract. / Returns or creates the child at index under the auto-growth rules above.
| pjson & ByteDance::pjson::operator[] | ( | const std::string & | aString | ) |
operator[] is a direct builder API. A key access changes a non-object into an object and creates a missing null child. An index access changes a non-array into an array; negative indexes count from the end and clamp before the beginning to zero, while indexes past the end grow the array with null children. A single access that would create more than one million children throws std::length_error before mutation. Use find()/tryGet() for reads. / Returns or creates the child at aString.
Public API member operator[]; see the API overview for its contract. / Returns or creates the child at aSkey; throws std::invalid_argument for null.
| pjson & ByteDance::pjson::operator[] | ( | int | index | ) |
Public API member operator[]; see the API overview for its contract.
|
static |
Public API member ParseOptions; see the API overview for its contract. / Parses aStr with aAlloc and reports the first failure in aError.
|
static |
Public API member ParseOptions; see the API overview for its contract. / Parses aStr and reports the first failure in aError.
|
static |
Public API member ParseOptions; see the API overview for its contract. / Buffers aIn, then parses with allocator-backed nodes and wrappers.
|
static |
Public API member ParseOptions; see the API overview for its contract.
|
static |
Allocator-aware DOM parsing routes root/child nodes and string/array/ object wrapper objects through borrowed aAlloc. Standard-container backing buffers still use their standard allocators, as described by Allocator above. aAlloc must outlive the returned tree. / Parses aStr with allocator-backed nodes and wrapper objects.
Public API member ParseOptions; see the API overview for its contract. / Parses a byte span with allocator-backed nodes and wrapper objects.
|
static |
Each parse accepts exactly one JSON value followed only by whitespace. In-memory parse failures return an empty pointer; diagnostic overloads reset aError and describe the first failure. A byte span may contain embedded NUL bytes, but a null aSrc is always an error. / Parses aStr into an owning tree using the default allocator.
Public API member ParseOptions; see the API overview for its contract. / Parses the aSize-byte span at aSrc using the default allocator.
|
static |
Public API member ParseOptions; see the API overview for its contract. / Parses a byte span with aAlloc and reports the first failure in aError.
|
static |
Public API member ParseOptions; see the API overview for its contract. / Parses the aSize-byte span and reports the first failure in aError.
|
static |
Public API member ParseOptions; see the API overview for its contract. / SAX-parses aStr and reports failure or cancellation in aError.
|
static |
Public API member ParseOptions; see the API overview for its contract. True streaming SAX parse: reads the istream incrementally and never buffers the full document in memory. / Incrementally parses aIn and emits events to aHandler.
|
static |
SAX parsing retains neither aHandler nor callback arguments. It returns false for invalid input, cancellation, stream failure, or a handler exception; callbacks already delivered before failure are not undone. / Parses aStr and emits its events to aHandler without building a DOM.
Public API member ParseOptions; see the API overview for its contract. / Parses the aSize-byte span and emits its events to aHandler.
|
static |
Public API member ParseOptions; see the API overview for its contract. / SAX-parses a byte span and reports failure or cancellation in aError.
|
static |
Public API member ParseOptions; see the API overview for its contract. / Incrementally SAX-parses aIn and reports failure or cancellation in aError.
|
static |
Public API member ParseOptions; see the API overview for its contract.
|
static |
Public API member ParseOptions; see the API overview for its contract. / Buffers and parses aIn with aAlloc, reporting ordinary failures in aError.
|
static |
parseStream() buffers the document in chunks while enforcing maxInputBytes. Stream or temporary-buffer exceptions may propagate. / Buffers and parses one document from aIn using the default allocator.
Public API member ParseOptions; see the API overview for its contract. / Buffers and parses aIn, reporting ordinary parse/read failures in aError.
|
static |
Public API member ParseOptions; see the API overview for its contract.
|
static |
Public API member ParseOptions; see the API overview for its contract.
| void ByteDance::pjson::reset | ( | ) |
Public API member reset; see the API overview for its contract. / Replaces the value with the empty/default value of a valid jsonType.
Public API member resetTo; see the API overview for its contract. / Calls resetTo() only when the type differs, otherwise preserving contents.
| size_t ByteDance::pjson::size | ( | ) | const |
Public API member size; see the API overview for its contract. / Returns whether size() is zero; consequently all scalar values are empty.
Public API member swap; see the API overview for its contract. / Returns the borrowed allocator bound to this value.
| std::string ByteDance::pjson::toString | ( | ) | const |
Non-finite stored doubles serialize as JSON null. Invalid UTF-8 in a string value or object key is a serialization failure: toString() throws, while write() sets failbit (and may propagate stream exceptions). toString() may also throw for allocation or length failure. / Returns compact JSON using the default serialization options.
Public API member toString; see the API overview for its contract. / Returns JSON serialized according to aOpts.
| std::string ByteDance::pjson::toString | ( | const SerializeOptions & | aOpts | ) | const |
Public API member toString; see the API overview for its contract. / Writes compact JSON to aOut using the default serialization options.
Public API member tryGet; see the API overview for its contract. / Copies a string only when this node stores jsonString.
Public API member tryGet; see the API overview for its contract. / Copies the string child at non-null aKey.
Public API member tryGet; see the API overview for its contract. / Extracts the boolean child at non-null aKey.
Public API member tryGet; see the API overview for its contract. / Extracts the numeric child at non-null aKey as a double.
Public API member tryGet; see the API overview for its contract. / Borrows a view of the string child at non-null aKey.
| bool ByteDance::pjson::tryGet | ( | const char * | aKey, |
| StringView & | aResult | ||
| ) | const |
Public API member tryGet; see the API overview for its contract.
Public API member tryGet; see the API overview for its contract. / Copies the string child at aKey.
Public API member tryGet; see the API overview for its contract. / Extracts the boolean child at aKey.
Strict typed child access layered on find() and node-level tryGet(). Missing/null keys, invalid indexes, and type mismatches leave aResult unchanged. Negative indexes count from the end. / Extracts the integer child at aKey without mutating this object.
Public API member tryGet; see the API overview for its contract. / Extracts the numeric child at aKey as a double.
Public API member tryGet; see the API overview for its contract. / Borrows a view of the string child at aKey.
| bool ByteDance::pjson::tryGet | ( | const std::string & | aKey, |
| StringView & | aResult | ||
| ) | const |
Public API member tryGet; see the API overview for its contract.
Public API member tryGet; see the API overview for its contract. / Extracts a boolean only when this node stores jsonBoolean.
Public API member tryGet; see the API overview for its contract. / Copies the string array child at aIndex.
Public API member tryGet; see the API overview for its contract. / Extracts the boolean array child at aIndex.
Public API member tryGet; see the API overview for its contract. / Extracts the numeric array child at aIndex as a double.
Public API member tryGet; see the API overview for its contract. / Borrows a view of the string array child at aIndex.
|
noexcept |
Public API member tryGet; see the API overview for its contract.
Strict typed access to this node. On a type mismatch, returns false and leaves aResult unchanged. Integers may widen to double; no other coercions are performed. StringView avoids a string copy. / Extracts an integer only when this node stores jsonNumberInt.
Public API member tryGet; see the API overview for its contract. / Extracts a numeric value, widening a stored integer when necessary.
| bool ByteDance::pjson::tryGet | ( | std::string & | aResult | ) | const |
Public API member tryGet; see the API overview for its contract. / Borrows a string view only when this node stores jsonString.
|
noexcept |
Public API member tryGet; see the API overview for its contract.
|
noexcept |
Validates this value against a schema that is itself a pjson object, using the documented JSON Schema subset; this is not a complete draft implementation. Returns true when the value conforms. Never throws. The second form appends reported keyword failures rather than stopping at the first. Errors inside non-selected anyOf/oneOf/not branches are intentionally suppressed, and a resource-budget failure can stop further validation.
Supported keywords: type, enum, const, $ref (local JSON Pointer fragments), properties, patternProperties, propertyNames, required, dependentRequired, dependencies, additionalProperties, minProperties, maxProperties, items, minItems, maxItems, uniqueItems, minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, minLength, maxLength, pattern, format, allOf, anyOf, oneOf, not. A boolean schema (true/false) accepts/rejects everything. Unknown keywords and unsupported keyword shapes are ignored. Both inputs are borrowed and unchanged; the collecting overload appends to aErrors without clearing existing entries. Resource aborts may stop collection. / Returns whether this value satisfies aSchema under aOpts. Public API member SchemaOptions; see the API overview for its contract. / Validates and appends discovered failures to aErrors.
|
noexcept |
Public API member SchemaOptions; see the API overview for its contract.
| void ByteDance::pjson::write | ( | std::ostream & | aOut | ) | const |
Public API member write; see the API overview for its contract. / Writes JSON configured by aOpts to aOut.
| void ByteDance::pjson::write | ( | std::ostream & | aOut, |
| const SerializeOptions & | aOpts | ||
| ) | const |
Public API member write; see the API overview for its contract.