34#define PJSON_VERSION_MAJOR 2
35#define PJSON_VERSION_MINOR 0
36#define PJSON_VERSION_PATCH 0
37#define PJSON_VERSION "2.0.0"
38#define PJSON_ABI_VERSION 2
40#if defined(_WIN32) && defined(PJSON_SHARED)
41#if defined(PJSON_BUILDING_LIBRARY)
42#define PJSON_API __declspec(dllexport)
44#define PJSON_API __declspec(dllimport)
46#elif defined(PJSON_SHARED) && (defined(__GNUC__) || defined(__clang__))
47#define PJSON_API __attribute__((visibility("default")))
105 StringAllocation = 1,
107 ObjectAllocation = 3,
108 ImplementationAllocation = 4
116 virtual void deallocate(
void* aPtr,
size_t aSize,
size_t aAlignment,
301 bool canSwap(const
pjson& aOther) const noexcept;
309 std::
string toString() const;
316 void write(std::ostream& aOut) const;
329 bool isString() const;
331 bool isNumber() const;
337 bool isInteger() const;
339 bool isDouble() const;
343 bool isArray() const;
345 bool isObject() const;
359 const
char* data() const noexcept;
361 size_t size() const noexcept;
363 bool empty() const noexcept;
368 StringView(const
char* aData,
size_t aSize) noexcept;
381 bool tryGet(int64_t& aResult) const noexcept;
383 bool tryGet(uint64_t& aResult) const noexcept;
385 bool tryGet(
double& aResult) const noexcept;
387 bool tryGet(
bool& aResult) const noexcept;
389 bool tryGet(std::
string& aResult) const;
402 std::vector<std::
string> keys() const;
406 typedef
bool (*ConstMemberVisitor)(
StringView aKey, const
pjson& aValue,
void* aContext);
410 typedef
bool (*ConstElementVisitor)(const
pjson& aValue,
void* aContext);
412 typedef
bool (*ElementVisitor)(
pjson& aValue,
void* aContext);
421 bool forEachMember(ConstMemberVisitor aVisitor,
void* aContext) const;
423 bool forEachMember(MemberVisitor aVisitor,
void* aContext);
425 bool forEachElement(ConstElementVisitor aVisitor,
void* aContext) const;
427 bool forEachElement(ElementVisitor aVisitor,
void* aContext);
431 bool hasKey(const std::
string& aKey) const;
433 bool hasKey(const
char* aKey) const;
435 bool contains(const std::
string& aKey) const;
437 bool contains(const
char* aKey) const;
439 bool hasIndex(
int aIndex) const noexcept;
445 pjson* find(const std::
string& aKey);
449 const
pjson* find(const std::
string& aKey) const;
451 const
pjson* find(const
char* aKey) const;
459 const
pjson* find(
int aIndex) const noexcept;
461 pjson* findIndex(
size_t aIndex) noexcept;
463 const
pjson* findIndex(
size_t aIndex) const noexcept;
469 static std::
string escapePointerToken(const std::
string& aToken);
471 pjson* findPointer(const std::
string& aPointer);
473 const
pjson* findPointer(const std::
string& aPointer) const;
479 pjson* findPointer(const
char* aPointer);
481 const
pjson* findPointer(const
char* aPointer) const;
491 bool tryGet(const std::
string& aKey, int64_t& aResult) const;
493 bool tryGet(const std::
string& aKey, uint64_t& aResult) const;
495 bool tryGet(const std::
string& aKey,
double& aResult) const;
497 bool tryGet(const std::
string& aKey,
bool& aResult) const;
499 bool tryGet(const std::
string& aKey, std::
string& aResult) const;
501 bool tryGet(const std::
string& aKey,
StringView& aResult) const;
504 bool tryGet(const
char* aKey, int64_t& aResult) const;
506 bool tryGet(const
char* aKey, uint64_t& aResult) const;
508 bool tryGet(const
char* aKey,
double& aResult) const;
510 bool tryGet(const
char* aKey,
bool& aResult) const;
512 bool tryGet(const
char* aKey, std::
string& aResult) const;
517 bool tryGet(
int aIndex, int64_t& aResult) const noexcept;
519 bool tryGet(
int aIndex, uint64_t& aResult) const noexcept;
521 bool tryGet(
int aIndex,
double& aResult) const noexcept;
523 bool tryGet(
int aIndex,
bool& aResult) const noexcept;
525 bool tryGet(
int aIndex, std::
string& aResult) const;
539 pjson& operator[](const std::
string& aString);
541 pjson& operator[](const
char* aSkey);
568 const
pjson& at(const std::
string& aKey) const;
572 const
pjson& at(
size_t aIndex) const;
583 pjson& insertOrAssign(const std::
string& aKey, const
pjson& aValue);
585 pjson& insertOrAssign(const std::
string& aKey,
pjson&& aValue);
595 pjson& operator=(const std::
string& aString);
597 pjson& operator=(const
char* aCString);
603 pjson& operator=(const
unsigned int aUInt);
607 pjson& operator=(const
unsigned short aUInt);
611 pjson& operator=(const
unsigned long aUInt);
613 pjson& operator=(const
long long aInt);
615 pjson& operator=(const
unsigned long long aUInt);
617 pjson& operator=(const
float aFloat);
619 pjson& operator=(const
double aDouble);
621 pjson& operator=(const
long double aDouble);
626 pjson& operator=(const std::vector<std::
string>& aValueArray);
628 pjson& operator=(const std::vector<
bool>& aValueArray);
630 pjson& operator=(const std::vector<
int>& aValueArray);
632 pjson& operator=(const std::vector<
unsigned int>& aValueArray);
634 pjson& operator=(const std::vector<
short>& aValueArray);
636 pjson& operator=(const std::vector<
unsigned short>& aValueArray);
638 pjson& operator=(const std::vector<
long>& aValueArray);
640 pjson& operator=(const std::vector<
unsigned long>& aValueArray);
642 pjson& operator=(const std::vector<
long long>& aValueArray);
644 pjson& operator=(const std::vector<
unsigned long long>& aValueArray);
646 pjson& operator=(const std::vector<
float>& aValueArray);
648 pjson& operator=(const std::vector<
double>& aValueArray);
650 pjson& operator=(const std::vector<
long double>& aValueArray);
655 pjson& operator+=(const std::
string& aValue);
657 pjson& operator+=(const
char* aValue);
659 pjson& operator+=(const
bool aValue);
661 pjson& operator+=(const
int aValue);
663 pjson& operator+=(const
unsigned int aValue);
665 pjson& operator+=(const
short aValue);
667 pjson& operator+=(const
unsigned short aValue);
669 pjson& operator+=(const
long aValue);
671 pjson& operator+=(const
unsigned long aValue);
673 pjson& operator+=(const
long long aValue);
675 pjson& operator+=(const
unsigned long long aValue);
677 pjson& operator+=(const
float aValue);
679 pjson& operator+=(const
double aValue);
681 pjson& operator+=(const
long double aValue);
686 pjson& operator+=(const std::vector<std::
string>& aValueArray);
688 pjson& operator+=(const std::vector<
bool>& aValueArray);
690 pjson& operator+=(const std::vector<
int>& aValueArray);
692 pjson& operator+=(const std::vector<
unsigned int>& aValueArray);
694 pjson& operator+=(const std::vector<
short>& aValueArray);
696 pjson& operator+=(const std::vector<
unsigned short>& aValueArray);
698 pjson& operator+=(const std::vector<
long>& aValueArray);
700 pjson& operator+=(const std::vector<
unsigned long>& aValueArray);
702 pjson& operator+=(const std::vector<
long long>& aValueArray);
704 pjson& operator+=(const std::vector<
unsigned long long>& aValueArray);
706 pjson& operator+=(const std::vector<
float>& aValueArray);
708 pjson& operator+=(const std::vector<
double>& aValueArray);
710 pjson& operator+=(const std::vector<
long double>& aValueArray);
715 bool erase(const std::
string& aKey);
717 bool erase(const
char* aKey);
719 bool erase(
size_t aIndex);
734 bool applyMergePatch(const
pjson& aPatch,
745 bool operator==(const
pjson& aOther) const;
747 bool operator!=(const
pjson& aOther) const;
759 bool tryCompareNumber(const
pjson& aOther,
int& aOrder) const noexcept;
774 friend struct pjsonImpl;
Minimal C++11-compatible, non-owning view of a JSON string.
StringView() noexcept
Constructs an empty view with data() == nullptr.
Owning, mutable JSON value with deep-copy semantics.
static const char * getVersion()
Returns the process-lifetime semantic-version string for this library.
@ jsonBoolean
Boolean value.
@ jsonNumberDouble
Binary64 number value.
@ jsonString
UTF-8 string value.
@ jsonNumberInt
Signed 64-bit integer value.
@ jsonNumberUInt
Unsigned 64-bit integer value.
@ jsonArray
Ordered array value.
@ jsonObject
Object with unique string keys.
Namespace containing the pjson public API.
Runtime allocator for persistent DOM storage.
virtual ~Allocator()
Enables destruction through an Allocator base pointer.
AllocationKind
Identifies the purpose and matching deallocation contract of storage.
virtual void deallocate(void *aPtr, size_t aSize, size_t aAlignment, AllocationKind aKind) noexcept=0
Releases a non-null allocation using its original size, alignment, and kind.
virtual void * allocate(size_t aSize, size_t aAlignment, AllocationKind aKind)=0
Returns non-null aligned storage or throws; returning null is unsupported.
Structured JSON Patch (RFC 6902) / Merge Patch (RFC 7396) failure.
std::string token
Decoded failing pointer token when available.
size_t opIndex
Zero-based index of the failing operation.
bool ok
True exactly when code is Ok.
std::string from
Source pointer when available.
std::string message
Human-readable diagnostic; wording is not stable. Constructs a successful patch state with no operati...
Code code
Stable machine-readable result category.
std::string path
Destination pointer when available.
std::string op
Operation name when available.
Code
Stable categories for programmatic JSON Patch failure handling.
@ MissingFrom
A copy or move lacks a string from member.
@ MoveIntoDescendant
A move destination lies under its source.
@ MissingValue
An add, replace, or test lacks value.
@ InvalidOp
The operation name is unsupported.
@ InvalidArrayIndex
An array path token is not a valid index.
@ AllocationFailure
Patch application could not allocate.
@ ArrayIndexOutOfRange
An array path token exceeds valid bounds.
@ ResourceLimit
A configured patch-work limit was reached.
@ MoveRootNotAllowed
A move attempts to remove the document root.
@ InvalidPath
The destination JSON Pointer is invalid.
@ MissingOp
An operation lacks a string op member.
@ TestFailed
A test operation did not compare equal.
@ InvalidPatchDocument
The patch document is not an array.
@ OperationNotObject
An operation entry is not an object.
@ MissingPath
An operation lacks a string path member.
@ Ok
Patch application succeeded.
@ TargetMissing
A required source, parent, or target is absent.
@ InvalidFrom
The source JSON Pointer is invalid.
size_t tokenIndex
Zero-based index of the failing pointer token.
Bounds transactional patch amplification.
size_t maxClonedBytes
Clone-byte ceiling; zero selects the hard 64 MiB limit.
size_t maxOperations
Operation ceiling; zero selects the hard 10,000 limit.
size_t maxClonedNodes
Clone-node ceiling; zero selects the hard 1,000,000 limit.
size_t maxWork
Work ceiling; zero selects the hard 1,000,000 limit. Selects the documented finite default limits.
Structured JSON Pointer (RFC 6901) lookup failure.
size_t tokenIndex
Zero-based index of the failing token.
Code
Stable categories for programmatic JSON Pointer failure handling.
@ InvalidSyntax
The pointer does not begin with slash or is malformed.
@ ArrayIndexOutOfRange
An array token exceeds the current array bounds.
@ AllocationFailure
Diagnostic construction could not allocate.
@ InvalidEscape
A token contains an invalid tilde escape.
@ MissingTarget
An object member or array element does not exist.
@ AppendTokenNotAllowed
The append token is invalid for lookup.
@ InvalidArrayIndex
An array token is not a canonical non-negative index.
@ ExpectedContainer
Traversal encountered a scalar before the final token.
std::string token
Decoded failing token when available.
bool ok
True exactly when code is Ok.
std::string message
Human-readable diagnostic; wording is not stable. Constructs a successful lookup state with no pointe...
std::string pointer
Pointer text supplied by the caller.
Code code
Stable machine-readable result category.
Structured outcome for the non-throwing serialization APIs.
void reset() noexcept
Resets the result to success.
Code
Stable categories for programmatic serialization failure handling.
@ NonFiniteNumber
NaN or infinity was rejected by the active policy.
@ OutputLimit
maxOutputBytes or representable output size was exceeded.
@ None
Serialization succeeded.
@ StreamFailure
The destination stream rejected a physical write.
@ AllocationFailure
Temporary serialization storage could not be allocated.
@ InvalidUtf8
A stored string or object key is not valid UTF-8.
Code code
Stable machine-readable result category.
std::string message
Human-readable diagnostic; empty on success. Constructs a successful serialization result.
Controls JSON serialization.
NonFinitePolicy nonFinite
Policy for NaN and infinity values.
size_t maxOutputBytes
Output ceiling; zero explicitly means unlimited.
char indentCharacter
Space or tab; invalid values are treated as space.
static SerializeOptions prettyPrinted()
Returns the defaults with pretty printing enabled.
size_t indentWidth
Indentation characters per nesting level.
bool escapeNonAscii
Emits non-ASCII code points as Unicode escapes.
bool pretty
Enables line breaks and indentation.
SerializeOptions()
Selects compact output, two-space indentation, and non-finite rejection.
NonFinitePolicy
Selects how stored NaN and infinity values are represented.
@ NonFiniteToNull
Emit non-finite values as JSON null.
@ RejectNonFinite
Fail because JSON has no non-finite number literal.