32#define PJSON_VERSION_MAJOR 1
33#define PJSON_VERSION_MINOR 0
34#define PJSON_VERSION_PATCH 0
35#define PJSON_VERSION "1.0.0"
107 typedef std::unique_ptr<pjson, ValueDeleter>
unique_ptr;
750 bool _allocatorOwnedNode;
757 ObjectStorage* _pValueMap;
758 ArrayStorage* _pValueArray;
762 std::string* _pValueString;
Minimal C++11-compatible, non-owning view of a JSON string. A view aliases bytes owned by this pjson ...
StringView() noexcept
Public API member StringView; see the API overview for its contract. / Returns the borrowed first byt...
Owning, mutable JSON value with deep-copy semantics.
jsonType getType() const
Public API member getType; see the API overview for its contract. / Returns whether this node is null...
void resetIfNeeded(jsonType aeType)
Public API member resetIfNeeded; see the API overview for its contract. Same-allocator swap is O(1)....
bool isInt() const
Public API member isInt; see the API overview for its contract. / Returns whether this node stores a ...
pjson & operator=(const pjson &aFrom)
Public API member operator=; see the API overview for its contract. / Moves aFrom while preserving th...
void reset()
Public API member reset; see the API overview for its contract. / Replaces the value with the empty/d...
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 ...
std::vector< std::string > keys() const
Public API member keys; see the API overview for its contract.
void swap(pjson &aOther) noexcept
Public API member swap; see the API overview for its contract. / Returns the borrowed allocator bound...
~pjson()
Public API member ~pjson; see the API overview for its contract. / Deep-copies aFrom using aFrom's bo...
bool isObject() const
Public API member isObject; 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,...
void write(std::ostream &aOut) const
Public API member write; see the API overview for its contract. / Writes JSON configured by aOpts to ...
std::unique_ptr< pjson, ValueDeleter > unique_ptr
Public API member unique_ptr; 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 retur...
void resetTo(jsonType aeType)
Public API member resetTo; see the API overview for its contract. / Calls resetTo() only when the typ...
bool isBool() const
Public API member isBool; see the API overview for its contract. / Returns whether this node stores a...
pjson(pjson &&aFrom, Allocator &aAlloc)
Public API member pjson; see the API overview for its contract. / Deep-copies aFrom while preserving ...
static pjson::unique_ptr parseStream(std::istream &aIn, const ParseOptions &aOpts=ParseOptions())
parseStream() buffers the document in chunks while enforcing maxInputBytes. Stream or temporary-buffe...
bool tryGet(int64_t &aResult) const noexcept
Strict typed access to this node. On a type mismatch, returns false and leaves aResult unchanged....
pjson(Allocator &aAlloc) noexcept
Public API member pjson; see the API overview for its contract. / Destroys this value and its complet...
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....
bool isNumber() const
Public API member isNumber; see the API overview for its contract. / Returns whether this node stores...
pjson(pjson &&aFrom) noexcept
Public API member pjson; see the API overview for its contract. / Transfers in O(1) when allocators m...
bool isArray() const
Public API member isArray; see the API overview for its contract. / Returns whether this node stores ...
pjson & operator=(pjson &&aFrom)
Public API member operator=; see the API overview for its contract. / Deep-copies aFrom while preserv...
Allocator & getAllocator() const noexcept
Public API member getAllocator; see the API overview for its contract. / Returns whether swap(aOther)...
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 abs...
static std::string escapePointerToken(const std::string &aToken)
RFC 6901 lookup. The empty pointer addresses this value; every non-empty pointer must begin with '/'....
pjson * findPointer(const std::string &aPointer)
Public API member findPointer; see the API overview for its contract. / Resolves aPointer and returns...
pjson(const pjson &aFrom)
Public API member pjson; see the API overview for its contract. / Deep-copies aFrom into borrowed aAl...
bool isDouble() const
Public API member isDouble; see the API overview for its contract. / Returns whether this node stores...
pjson(const pjson &aFrom, Allocator &aAlloc)
Public API member pjson; see the API overview for its contract. / Transfers aFrom's storage and alloc...
bool hasIndex(int aIndex) const noexcept
Public API member hasIndex; see the API overview for its contract.
void clear()
Public API member clear; see the API overview for its contract.
static const char * getVersion()
Public API member getVersion; see the API overview for its contract.
bool canSwap(const pjson &aOther) const noexcept
Public API member canSwap; 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...
bool isNull() const
Public API member isNull; see the API overview for its contract. / Returns whether this node stores a...
std::string toString() const
Non-finite stored doubles serialize as JSON null. Invalid UTF-8 in a string value or object key is a ...
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...
friend struct pjsonImpl
The parser, schema validator, and encoding routines live entirely in pjson.cpp as the pjsonImpl helpe...
void copyFrom(const pjson &aFrom)
Public API member copyFrom; see the API overview for its contract. / Destroys the current contents an...
bool isString() const
Public API member isString; see the API overview for its contract. / Returns whether this node stores...
bool empty() const
Public API member empty; see the API overview for its contract. / Empties a container without changin...
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 erasu...
pjson()
Public API member pjson; see the API overview for its contract. / Constructs null bound to borrowed a...
size_t size() const
Public API member size; see the API overview for its contract. / Returns whether size() is zero; cons...
jsonType
JSON value kind. Numbers are stored in one of two representations: whole numbers as a 64-bit signed i...
@ jsonBoolean
JSON value or policy constant.
@ jsonNumberDouble
JSON value or policy constant.
@ jsonString
JSON value or policy constant.
@ jsonNumberInt
JSON value or policy constant.
@ jsonNull
stable zero-valued discriminator for the default state
bool hasKey(const std::string &aKey) const
Public API member hasKey; see the API overview for its contract. / Returns whether this object contai...
Namespace containing the pjson public API.
Runtime allocator for persistent DOM storage. The allocator is non-owning and must outlive every pjso...
virtual ~Allocator()
Public API member ~Allocator; see the API overview for its contract. / Returns non-null aligned stora...
AllocationKind
Selects one of the public JSON policies.
@ ObjectAllocation
JSON value or policy constant.
@ StringAllocation
JSON value or policy constant.
@ ArrayAllocation
JSON value or policy constant.
@ NodeAllocation
JSON value or policy constant.
virtual void deallocate(void *aPtr, size_t aSize, size_t aAlignment, AllocationKind aKind) noexcept=0
Public API member member; see the API overview for its contract.
virtual void * allocate(size_t aSize, size_t aAlignment, AllocationKind aKind)=0
Public API member allocate; see the API overview for its contract. / Releases a non-null allocation u...
Filled in by the error-reporting parse() overloads. ok is true when parsing succeeded; otherwise offs...
std::string message
Public API member message; see the API overview for its contract. / Constructs a success state at the...
bool ok
Public API member ok; see the API overview for its contract.
size_t column
Public API member column; see the API overview for its contract.
ParseError()
Public API member ParseError; see the API overview for its contract.
size_t line
Public API member line; see the API overview for its contract.
size_t offset
Public API member offset; see the API overview for its contract.
Bounds how much work a parse may do. Parsing always enforces RFC 8259 conformance and rejects:
size_t maxNodes
max JSON values created (0 = unlimited)
DuplicateKeyPolicy
Selects one of the public JSON policies.
@ KeepFirstDuplicate
JSON value or policy constant.
@ KeepLastDuplicate
JSON value or policy constant.
@ RejectDuplicateKeys
JSON value or policy constant.
size_t maxInputBytes
max input length in bytes (0 = unlimited)
ParseOptions()
Public API member ParseOptions; see the API overview for its contract.
DuplicateKeyPolicy duplicateKeys
Public API member duplicateKeys; see the API overview for its contract. / Selects duplicate rejection...
int maxDepth
nesting limit; values <= 0 enforce a one-level limit
Structured JSON Patch (RFC 6902) / Merge Patch (RFC 7396) failure. Patch application is atomic: failu...
std::string token
Public API member token; see the API overview for its contract.
size_t opIndex
Public API member opIndex; see the API overview for its contract.
bool ok
Public API member ok; see the API overview for its contract.
PatchError()
Public API member PatchError; see the API overview for its contract.
std::string from
Public API member from; see the API overview for its contract.
std::string message
Public API member message; see the API overview for its contract. / Constructs a successful patch sta...
Code code
Public API member code; see the API overview for its contract.
std::string path
Public API member path; see the API overview for its contract.
std::string op
Public API member op; see the API overview for its contract.
Code
Selects one of the public JSON policies.
@ MissingFrom
JSON value or policy constant.
@ MoveIntoDescendant
JSON value or policy constant.
@ MissingValue
JSON value or policy constant.
@ InvalidOp
JSON value or policy constant.
@ InvalidArrayIndex
JSON value or policy constant.
@ AllocationFailure
JSON value or policy constant.
@ ArrayIndexOutOfRange
JSON value or policy constant.
@ ResourceLimit
JSON value or policy constant.
@ MoveRootNotAllowed
JSON value or policy constant.
@ InvalidPath
JSON value or policy constant.
@ MissingOp
JSON value or policy constant.
@ InternalError
JSON value or policy constant.
@ TestFailed
JSON value or policy constant.
@ InvalidPatchDocument
JSON value or policy constant.
@ OperationNotObject
JSON value or policy constant.
@ MissingPath
JSON value or policy constant.
@ Ok
JSON value or policy constant.
@ TargetMissing
JSON value or policy constant.
@ InvalidFrom
JSON value or policy constant.
size_t tokenIndex
Public API member tokenIndex; see the API overview for its contract.
Bounds transactional patch amplification. Zero selects the documented built-in ceiling rather than di...
size_t maxClonedBytes
default/hard ceiling: 64 MiB
size_t maxOperations
default/hard ceiling: 10,000
size_t maxClonedNodes
default/hard ceiling: 1,000,000
size_t maxWork
default/hard ceiling: 1,000,000
PatchOptions()
Public API member PatchOptions; see the API overview for its contract.
Structured JSON Pointer (RFC 6901) lookup failure. tokenIndex is zero-based and token is the decoded ...
size_t tokenIndex
Public API member tokenIndex; see the API overview for its contract.
Code
Selects one of the public JSON policies.
@ InvalidSyntax
JSON value or policy constant.
@ ArrayIndexOutOfRange
JSON value or policy constant.
@ InternalError
JSON value or policy constant.
@ AllocationFailure
JSON value or policy constant.
@ InvalidEscape
JSON value or policy constant.
@ MissingTarget
JSON value or policy constant.
@ AppendTokenNotAllowed
JSON value or policy constant.
@ InvalidArrayIndex
JSON value or policy constant.
@ ExpectedContainer
JSON value or policy constant.
@ Ok
JSON value or policy constant.
std::string token
Public API member token; see the API overview for its contract.
bool ok
Public API member ok; see the API overview for its contract.
std::string message
Public API member message; see the API overview for its contract. / Constructs a successful lookup st...
std::string pointer
Public API member pointer; see the API overview for its contract.
Code code
Public API member code; see the API overview for its contract.
PointerError()
Public API member PointerError; see the API overview for its contract.
Event sink for non-owning SAX parsing. Return false from any callback to cancel parsing; public parse...
virtual bool onDouble(double aValue)
Public API member onDouble; see the API overview for its contract. / Receives borrowed decoded string...
virtual bool onStartArray()
Public API member onStartArray; see the API overview for its contract. / Marks the end of an array; r...
virtual ~SaxHandler()
Public API member ~SaxHandler; see the API overview for its contract. / Receives a JSON null value; r...
virtual bool onInt(int64_t aValue)
Public API member onInt; see the API overview for its contract. / Receives a floating-point JSON numb...
virtual bool onStartObject()
Public API member onStartObject; see the API overview for its contract. / Receives a borrowed decoded...
virtual bool onString(const std::string &aValue)
Public API member onString; see the API overview for its contract. / Marks the beginning of an array;...
virtual bool onEndArray()
Public API member onEndArray; see the API overview for its contract. / Marks the beginning of an obje...
virtual bool onEndObject()
Public API member onEndObject; see the API overview for its contract.
virtual bool onKey(const std::string &aKey)
Public API member onKey; see the API overview for its contract. / Marks the end of an object; return ...
virtual bool onBool(bool aValue)
Public API member onBool; see the API overview for its contract. / Receives an integer-valued JSON nu...
virtual bool onNull()
Public API member onNull; see the API overview for its contract. / Receives a JSON boolean value; ret...
One schema-validation failure: path is a JSON Pointer to the offending node (e.g. "/address/zip",...
SchemaError()
Public API member SchemaError; see the API overview for its contract. / Constructs an error for aPath...
SchemaError(const std::string &aPath, const std::string &aMsg)
Public API member SchemaError; see the API overview for its contract.
std::string path
Public API member path; see the API overview for its contract.
std::string message
Public API member message; see the API overview for its contract. / Constructs an error with an empty...
Bounds schema regular-expression work. By default only a conservative, non-ambiguous ECMAScript subse...
static SchemaOptions trustedRegex()
Public API member trustedRegex; see the API overview for its contract.
bool allowUnsafeRegex
default false / Recursive depth (default 512); zero still selects the hard ceiling of 512.
size_t maxValidationWork
Public API member maxValidationWork; see the API overview for its contract. / Reported errors (defaul...
SchemaOptions()
Public API member SchemaOptions; see the API overview for its contract. / Disables only regex restric...
size_t maxErrors
Public API member maxErrors; see the API overview for its contract.
bool validateFormats
validate known string formats (default true) / Selects bounded safe-regex, traversal,...
size_t maxRegexSubjectBytes
0 = unlimited (default: 4096)
size_t maxValidationDepth
Public API member maxValidationDepth; see the API overview for its contract. / Resolved references (d...
size_t maxRegexPatternBytes
0 = unlimited (default: 256)
size_t maxRefResolutions
Public API member maxRefResolutions; see the API overview for its contract. / Validation work units (...
Controls JSON serialization. The default produces the same compact, ascending-key output as toString(...
KeyOrder
Selects one of the public JSON policies.
@ AscendingKeys
JSON value or policy constant.
@ DescendingKeys
JSON value or policy constant.
size_t maxOutputBytes
default 64 MiB; zero explicitly means unlimited
char indentCharacter
Public API member indentCharacter; see the API overview for its contract.
static SerializeOptions prettyPrinted()
Public API member prettyPrinted; see the API overview for its contract.
size_t indentWidth
Public API member indentWidth; see the API overview for its contract.
bool escapeNonAscii
Public API member escapeNonAscii; see the API overview for its contract.
KeyOrder keyOrder
Public API member keyOrder; see the API overview for its contract.
bool pretty
Public API member pretty; see the API overview for its contract.
SerializeOptions()
Public API member SerializeOptions; see the API overview for its contract. / Returns the defaults wit...
Stateless ownership for allocator-created nodes. Provenance is read from the node itself,...
void operator()(pjson *aValue) const noexcept
Public API member operator; see the API overview for its contract.