pjson 1.0.0
A small, owning JSON value for C++11
Loading...
Searching...
No Matches
ByteDance::pjson Class Reference

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, ValueDeleterunique_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.
 
pjsonoperator= (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.
 
pjsonoperator= (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.
 
AllocatorgetAllocator () 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.
 
pjsonfind (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.
 
pjsonfind (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 pjsonfind (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 pjsonfind (const char *aKey) const
 Public API member find; see the API overview for its contract.
 
pjsonfind (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 pjsonfind (int aIndex) const noexcept
 Public API member find; see the API overview for its contract.
 
pjsonfindPointer (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 pjsonfindPointer (const std::string &aPointer) const
 Public API member findPointer; see the API overview for its contract. / Resolves aPointer and reports lookup failure in aError.
 
pjsonfindPointer (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 pjsonfindPointer (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.
 
pjsonfindPointer (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 pjsonfindPointer (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.
 
pjsonfindPointer (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 pjsonfindPointer (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.
 
pjsonoperator[] (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.
 
pjsonoperator[] (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.
 
pjsonoperator[] (int index)
 Public API member operator[]; see the API overview for its contract.
 
pjsonoperator= (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.
 
pjsonoperator= (const char *aCString)
 Public API member operator=; see the API overview for its contract. / Replaces this value with aBool.
 
pjsonoperator= (const bool aBool)
 Public API member operator=; see the API overview for its contract. / Replaces this value with aInt.
 
pjsonoperator= (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.
 
pjsonoperator= (const double aDouble)
 Public API member operator=; see the API overview for its contract.
 
pjsonoperator= (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.
 
pjsonoperator= (const std::vector< bool > &aValueArray)
 Public API member operator=; see the API overview for its contract. / Replaces this value with a copied integer array.
 
pjsonoperator= (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.
 
pjsonoperator= (const std::vector< double > &aValueArray)
 Public API member operator=; see the API overview for its contract.
 
pjsonoperator+= (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.
 
pjsonoperator+= (const char *aValue)
 Public API member operator+=; see the API overview for its contract. / Appends aValue as a boolean child.
 
pjsonoperator+= (const bool aValue)
 Public API member operator+=; see the API overview for its contract. / Appends aValue as an integer child.
 
pjsonoperator+= (const int64_t aValue)
 Public API member operator+=; see the API overview for its contract. / Appends aValue as a double child.
 
pjsonoperator+= (const double aValue)
 Public API member operator+=; see the API overview for its contract.
 
pjsonoperator+= (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.
 
pjsonoperator+= (const std::vector< bool > &aValueArray)
 Public API member operator+=; see the API overview for its contract. / Appends every integer in aValueArray.
 
pjsonoperator+= (const std::vector< int64_t > &aValueArray)
 Public API member operator+=; see the API overview for its contract. / Appends every double in aValueArray.
 
pjsonoperator+= (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 chargetVersion ()
 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.
 

Detailed Description

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.

See also
https://github.com/Pico-Developer/pjson/tree/main/docs Tutorials
migration-nlohmann-json
migration-rapidjson

Definition at line 56 of file pjson.h.

Member Typedef Documentation

◆ unique_ptr

Public API member unique_ptr; see the API overview for its contract.

Definition at line 108 of file pjson.h.

Member Enumeration Documentation

◆ jsonType

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).

Enumerator
jsonNull 

stable zero-valued discriminator for the default state

jsonString 

JSON value or policy constant.

jsonNumberInt 

JSON value or policy constant.

jsonNumberDouble 

JSON value or policy constant.

jsonBoolean 

JSON value or policy constant.

jsonArray 

[ ] array

jsonObject 

{ ... } map

Definition at line 67 of file pjson.h.

Constructor & Destructor Documentation

◆ pjson() [1/6]

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.

◆ pjson() [2/6]

ByteDance::pjson::pjson ( Allocator aAlloc)
explicitnoexcept

Public API member pjson; see the API overview for its contract. / Destroys this value and its complete owned subtree.

◆ ~pjson()

ByteDance::pjson::~pjson ( )

Public API member ~pjson; see the API overview for its contract. / Deep-copies aFrom using aFrom's borrowed allocator.

◆ pjson() [3/6]

ByteDance::pjson::pjson ( const pjson aFrom)

Public API member pjson; see the API overview for its contract. / Deep-copies aFrom into borrowed aAlloc.

◆ pjson() [4/6]

ByteDance::pjson::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() [5/6]

ByteDance::pjson::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() [6/6]

ByteDance::pjson::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.

Member Function Documentation

◆ applyMergePatch() [1/2]

bool ByteDance::pjson::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.

◆ applyMergePatch() [2/2]

bool ByteDance::pjson::applyMergePatch ( const pjson aPatch,
PatchError aError,
const PatchOptions aOpts = PatchOptions() 
)
noexcept

Public API member PatchOptions; see the API overview for its contract.

◆ applyPatch() [1/2]

bool ByteDance::pjson::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.

Public API member PatchOptions; see the API overview for its contract. / Atomically applies RFC 6902 and reports failure details in aError.

◆ applyPatch() [2/2]

bool ByteDance::pjson::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.

◆ canSwap()

bool ByteDance::pjson::canSwap ( const pjson aOther) const
noexcept

Public API member canSwap; see the API overview for its contract.

◆ clear()

void ByteDance::pjson::clear ( )

Public API member clear; see the API overview for its contract.

◆ copyFrom()

void ByteDance::pjson::copyFrom ( const pjson aFrom)

Public API member copyFrom; see the API overview for its contract. / Destroys the current contents and becomes null.

◆ empty()

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.

◆ erase() [1/3]

bool ByteDance::pjson::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.

◆ erase() [2/3]

bool ByteDance::pjson::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.

Public API member erase; see the API overview for its contract. / Erases non-null aKey; null or a non-object returns false.

◆ erase() [3/3]

bool ByteDance::pjson::erase ( size_t  aIndex)

Public API member erase; see the API overview for its contract.

◆ escapePointerToken()

static std::string ByteDance::pjson::escapePointerToken ( const std::string &  aToken)
static

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.

◆ find() [1/6]

pjson * ByteDance::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.

◆ find() [2/6]

const pjson * ByteDance::pjson::find ( const char aKey) const

Public API member find; see the API overview for its contract.

◆ find() [3/6]

pjson * ByteDance::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.

Public API member find; see the API overview for its contract. / Returns the borrowed child at non-null aKey, or null on failure.

◆ find() [4/6]

const pjson * ByteDance::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.

◆ find() [5/6]

const pjson * ByteDance::pjson::find ( int  aIndex) const
noexcept

Public API member find; see the API overview for its contract.

◆ find() [6/6]

pjson * ByteDance::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.

Public API member find; see the API overview for its contract. / Returns the read-only borrowed array child at aIndex, or null on failure.

◆ findPointer() [1/8]

pjson * ByteDance::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.

◆ findPointer() [2/8]

const pjson * ByteDance::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.

◆ findPointer() [3/8]

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.

◆ findPointer() [4/8]

const pjson * ByteDance::pjson::findPointer ( const char aPointer,
PointerError aError 
) const

Public API member findPointer; see the API overview for its contract.

◆ findPointer() [5/8]

pjson * ByteDance::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.

◆ findPointer() [6/8]

const pjson * ByteDance::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.

◆ findPointer() [7/8]

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.

◆ findPointer() [8/8]

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.

◆ getAllocator()

Allocator & ByteDance::pjson::getAllocator ( ) const
noexcept

Public API member getAllocator; see the API overview for its contract. / Returns whether swap(aOther) can exchange contents.

◆ getType()

jsonType ByteDance::pjson::getType ( ) const

Public API member getType; see the API overview for its contract. / Returns whether this node is null.

◆ getVersion()

static const char * ByteDance::pjson::getVersion ( )
static

Public API member getVersion; see the API overview for its contract.

◆ hasIndex()

bool ByteDance::pjson::hasIndex ( int  aIndex) const
noexcept

Public API member hasIndex; see the API overview for its contract.

◆ hasKey() [1/2]

bool ByteDance::pjson::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.

◆ hasKey() [2/2]

bool ByteDance::pjson::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.

◆ isArray()

bool ByteDance::pjson::isArray ( ) const

Public API member isArray; see the API overview for its contract. / Returns whether this node stores an object.

◆ isBool()

bool ByteDance::pjson::isBool ( ) const

Public API member isBool; see the API overview for its contract. / Returns whether this node stores an array.

◆ isDouble()

bool ByteDance::pjson::isDouble ( ) const

Public API member isDouble; see the API overview for its contract. / Returns whether this node stores a boolean.

◆ isInt()

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.

◆ isNull()

bool ByteDance::pjson::isNull ( ) const

Public API member isNull; see the API overview for its contract. / Returns whether this node stores a string.

◆ isNumber()

bool ByteDance::pjson::isNumber ( ) const

Public API member isNumber; see the API overview for its contract. / Returns whether this node stores an integer representation.

◆ isObject()

bool ByteDance::pjson::isObject ( ) const

Public API member isObject; see the API overview for its contract.

◆ isString()

bool ByteDance::pjson::isString ( ) const

Public API member isString; see the API overview for its contract. / Returns whether this node stores either numeric representation.

◆ keys()

std::vector< std::string > ByteDance::pjson::keys ( ) const

Public API member keys; see the API overview for its contract.

◆ operator!=()

Public API member operator!=; see the API overview for its contract.

◆ operator+=() [1/9]

Public API member operator+=; see the API overview for its contract. / Appends aValue as an integer child.

◆ operator+=() [2/9]

Public API member operator+=; see the API overview for its contract. / Appends aValue as a boolean child.

◆ operator+=() [3/9]

Public API member operator+=; see the API overview for its contract.

◆ operator+=() [4/9]

Public API member operator+=; see the API overview for its contract. / Appends aValue as a double child.

◆ operator+=() [5/9]

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.

◆ operator+=() [6/9]

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.

◆ operator+=() [7/9]

pjson & ByteDance::pjson::operator+= ( const std::vector< double > &  aValueArray)

Public API member operator+=; see the API overview for its contract.

◆ operator+=() [8/9]

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.

◆ operator+=() [9/9]

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.

◆ operator=() [1/11]

Public API member operator=; see the API overview for its contract. / Replaces this value with aInt.

◆ operator=() [2/11]

Public API member operator=; see the API overview for its contract. / Replaces this value with aBool.

◆ operator=() [3/11]

Public API member operator=; see the API overview for its contract.

◆ operator=() [4/11]

Public API member operator=; see the API overview for its contract. / Replaces this value with aDouble; non-finite values serialize as null.

◆ operator=() [5/11]

Public API member operator=; see the API overview for its contract. / Moves aFrom while preserving this allocator; cross-allocator moves may allocate.

◆ operator=() [6/11]

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.

◆ operator=() [7/11]

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.

◆ operator=() [8/11]

pjson & ByteDance::pjson::operator= ( const std::vector< double > &  aValueArray)

Public API member operator=; see the API overview for its contract.

◆ operator=() [9/11]

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.

◆ operator=() [10/11]

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.

◆ operator=() [11/11]

Public API member operator=; see the API overview for its contract. / Deep-copies aFrom while preserving this value's allocator.

◆ operator==()

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==.

◆ operator[]() [1/3]

Public API member operator[]; see the API overview for its contract. / Returns or creates the child at index under the auto-growth rules above.

◆ operator[]() [2/3]

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.

◆ operator[]() [3/3]

Public API member operator[]; see the API overview for its contract.

◆ parse() [1/8]

static unique_ptr ByteDance::pjson::parse ( const char aSrc,
size_t  aSize,
Allocator aAlloc,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract. / Parses aStr with aAlloc and reports the first failure in aError.

◆ parse() [2/8]

static pjson::unique_ptr ByteDance::pjson::parse ( const char aSrc,
size_t  aSize,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract. / Parses aStr and reports the first failure in aError.

◆ parse() [3/8]

static unique_ptr ByteDance::pjson::parse ( const char aSrc,
size_t  aSize,
ParseError aError,
Allocator aAlloc,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract. / Buffers aIn, then parses with allocator-backed nodes and wrappers.

◆ parse() [4/8]

static pjson::unique_ptr ByteDance::pjson::parse ( const char aSrc,
size_t  aSize,
ParseError aError,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract.

◆ parse() [5/8]

static unique_ptr ByteDance::pjson::parse ( const std::string &  aStr,
Allocator aAlloc,
const ParseOptions aOpts = ParseOptions() 
)
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.

◆ parse() [6/8]

static pjson::unique_ptr ByteDance::pjson::parse ( const std::string &  aStr,
const ParseOptions aOpts = ParseOptions() 
)
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.

◆ parse() [7/8]

static unique_ptr ByteDance::pjson::parse ( const std::string &  aStr,
ParseError aError,
Allocator aAlloc,
const ParseOptions aOpts = ParseOptions() 
)
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.

◆ parse() [8/8]

static pjson::unique_ptr ByteDance::pjson::parse ( const std::string &  aStr,
ParseError aError,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract. / Parses the aSize-byte span and reports the first failure in aError.

◆ parseSax() [1/4]

static bool ByteDance::pjson::parseSax ( const char aSrc,
size_t  aSize,
SaxHandler aHandler,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract. / SAX-parses aStr and reports failure or cancellation in aError.

◆ parseSax() [2/4]

static bool ByteDance::pjson::parseSax ( const char aSrc,
size_t  aSize,
SaxHandler aHandler,
ParseError aError,
const ParseOptions aOpts = ParseOptions() 
)
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.

◆ parseSax() [3/4]

static bool ByteDance::pjson::parseSax ( const std::string &  aStr,
SaxHandler aHandler,
const ParseOptions aOpts = ParseOptions() 
)
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.

◆ parseSax() [4/4]

static bool ByteDance::pjson::parseSax ( const std::string &  aStr,
SaxHandler aHandler,
ParseError aError,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract. / SAX-parses a byte span and reports failure or cancellation in aError.

◆ parseSaxStream() [1/2]

static bool ByteDance::pjson::parseSaxStream ( std::istream &  aIn,
SaxHandler aHandler,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract. / Incrementally SAX-parses aIn and reports failure or cancellation in aError.

◆ parseSaxStream() [2/2]

static bool ByteDance::pjson::parseSaxStream ( std::istream &  aIn,
SaxHandler aHandler,
ParseError aError,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract.

◆ parseStream() [1/4]

static unique_ptr ByteDance::pjson::parseStream ( std::istream &  aIn,
Allocator aAlloc,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract. / Buffers and parses aIn with aAlloc, reporting ordinary failures in aError.

◆ parseStream() [2/4]

static pjson::unique_ptr ByteDance::pjson::parseStream ( std::istream &  aIn,
const ParseOptions aOpts = ParseOptions() 
)
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.

◆ parseStream() [3/4]

static unique_ptr ByteDance::pjson::parseStream ( std::istream &  aIn,
ParseError aError,
Allocator aAlloc,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract.

◆ parseStream() [4/4]

static pjson::unique_ptr ByteDance::pjson::parseStream ( std::istream &  aIn,
ParseError aError,
const ParseOptions aOpts = ParseOptions() 
)
static

Public API member ParseOptions; see the API overview for its contract.

◆ reset()

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.

◆ resetIfNeeded()

void ByteDance::pjson::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.

◆ resetTo()

void ByteDance::pjson::resetTo ( jsonType  aeType)

Public API member resetTo; see the API overview for its contract. / Calls resetTo() only when the type differs, otherwise preserving contents.

◆ size()

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.

◆ swap()

void ByteDance::pjson::swap ( pjson aOther)
noexcept

Public API member swap; see the API overview for its contract. / Returns the borrowed allocator bound to this value.

◆ toString() [1/2]

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.

◆ toString() [2/2]

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.

◆ tryGet() [1/20]

bool ByteDance::pjson::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.

◆ tryGet() [2/20]

bool ByteDance::pjson::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.

◆ tryGet() [3/20]

bool ByteDance::pjson::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.

◆ tryGet() [4/20]

bool ByteDance::pjson::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.

◆ tryGet() [5/20]

bool ByteDance::pjson::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.

◆ tryGet() [6/20]

bool ByteDance::pjson::tryGet ( const char aKey,
StringView aResult 
) const

Public API member tryGet; see the API overview for its contract.

◆ tryGet() [7/20]

bool ByteDance::pjson::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.

◆ tryGet() [8/20]

bool ByteDance::pjson::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.

◆ tryGet() [9/20]

bool ByteDance::pjson::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.

Public API member tryGet; see the API overview for its contract. / Extracts the numeric child at aKey as a double.

◆ tryGet() [10/20]

bool ByteDance::pjson::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.

◆ tryGet() [11/20]

bool ByteDance::pjson::tryGet ( const std::string &  aKey,
StringView aResult 
) const

Public API member tryGet; see the API overview for its contract.

◆ tryGet() [12/20]

bool ByteDance::pjson::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.

◆ tryGet() [13/20]

bool ByteDance::pjson::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.

◆ tryGet() [14/20]

bool ByteDance::pjson::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.

◆ tryGet() [15/20]

bool ByteDance::pjson::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.

◆ tryGet() [16/20]

bool ByteDance::pjson::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.

◆ tryGet() [17/20]

bool ByteDance::pjson::tryGet ( int  aIndex,
StringView aResult 
) const
noexcept

Public API member tryGet; see the API overview for its contract.

◆ tryGet() [18/20]

bool ByteDance::pjson::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.

Public API member tryGet; see the API overview for its contract. / Extracts a numeric value, widening a stored integer when necessary.

◆ tryGet() [19/20]

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.

◆ tryGet() [20/20]

bool ByteDance::pjson::tryGet ( StringView aResult) const
noexcept

Public API member tryGet; see the API overview for its contract.

◆ validate() [1/2]

bool ByteDance::pjson::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.

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.

◆ validate() [2/2]

bool ByteDance::pjson::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.

◆ write() [1/2]

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.

◆ write() [2/2]

void ByteDance::pjson::write ( std::ostream &  aOut,
const SerializeOptions aOpts 
) const

Public API member write; see the API overview for its contract.


The documentation for this class was generated from the following file: