Quick Links: |
#include <bdljsn_json.h>
Public Member Functions | |
BSLMF_NESTED_TRAIT_DECLARATION (Json, bslma::UsesBslmaAllocator) | |
BSLMF_NESTED_TRAIT_DECLARATION (Json, bslmf::IsBitwiseMoveable) | |
BSLMF_NESTED_TRAIT_DECLARATION (Json, bdlb::HasPrintMethod) | |
Json () | |
Json (bslma::Allocator *basicAllocator) | |
Json (const Json &original, bslma::Allocator *basicAllocator=0) | |
Json (bslmf::MovableRef< Json > original) | |
Json (bslmf::MovableRef< Json > original, bslma::Allocator *basicAllocator) | |
Json (const JsonArray &array, bslma::Allocator *basicAllocator=0) | |
Json (bslmf::MovableRef< JsonArray > array, bslma::Allocator *basicAllocator=0) | |
Json (bool boolean, bslma::Allocator *basicAllocator=0) | |
Json (const JsonNull &null, bslma::Allocator *basicAllocator=0) | |
Json (float number, bslma::Allocator *basicAllocator=0) | |
Json (double number, bslma::Allocator *basicAllocator=0) | |
Json (bdldfp::Decimal64 number, bslma::Allocator *basicAllocator=0) | |
Json (int number, bslma::Allocator *basicAllocator=0) | |
Json (unsigned int number, bslma::Allocator *basicAllocator=0) | |
Json (bsls::Types::Int64 number, bslma::Allocator *basicAllocator=0) | |
Json (bsls::Types::Uint64 number, bslma::Allocator *basicAllocator=0) | |
Json (const JsonNumber &number, bslma::Allocator *basicAllocator=0) | |
Json (bslmf::MovableRef< JsonNumber > number, bslma::Allocator *basicAllocator=0) | |
Json (const JsonObject &object, bslma::Allocator *basicAllocator=0) | |
Json (bslmf::MovableRef< JsonObject > object, bslma::Allocator *basicAllocator=0) | |
Json (const char *string, bslma::Allocator *basicAllocator=0) | |
Json (const bsl::string_view &string, bslma::Allocator *basicAllocator=0) | |
template<class STRING_TYPE > | |
Json (BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) string, bslma::Allocator *basicAllocator=0, typename bsl::enable_if< bsl::is_same< STRING_TYPE, bsl::string >::value >::type *=0) | |
Json & | operator= (const Json &rhs) |
Json & | operator= (bslmf::MovableRef< Json > rhs) |
Json & | operator= (float rhs) |
Json & | operator= (double rhs) |
Json & | operator= (bdldfp::Decimal64 rhs) |
Json & | operator= (int rhs) |
Json & | operator= (unsigned int rhs) |
Json & | operator= (bsls::Types::Int64 rhs) |
Json & | operator= (bsls::Types::Uint64 rhs) |
Json & | operator= (const JsonNumber &rhs) |
Json & | operator= (bslmf::MovableRef< JsonNumber > rhs) |
Json & | operator= (const char *rhs) |
Json & | operator= (const bsl::string_view &rhs) |
template<class STRING_TYPE > | |
bsl::enable_if< bsl::is_same < STRING_TYPE, bsl::string > ::value, Json >::type & | operator= (BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) rhs) |
Json & | operator= (bool rhs) |
Json & | operator= (const JsonObject &rhs) |
Json & | operator= (bslmf::MovableRef< JsonObject > rhs) |
Json & | operator= (const JsonArray &rhs) |
Json & | operator= (bslmf::MovableRef< JsonArray > rhs) |
Json & | operator= (const JsonNull &) |
Json & | operator= (bslmf::MovableRef< JsonNull >) |
JsonArray & | makeArray () |
JsonArray & | makeArray (const JsonArray &array) |
JsonArray & | makeArray (bslmf::MovableRef< JsonArray > array) |
bool & | makeBoolean () |
bool & | makeBoolean (bool boolean) |
void | makeNull () |
JsonNumber & | makeNumber () |
JsonNumber & | makeNumber (const JsonNumber &number) |
JsonNumber & | makeNumber (bslmf::MovableRef< JsonNumber > number) |
JsonObject & | makeObject () |
JsonObject & | makeObject (const JsonObject &object) |
JsonObject & | makeObject (bslmf::MovableRef< JsonObject > object) |
void | makeString (const char *string) |
void | makeString (const bsl::string_view &string) |
template<class STRING_TYPE > | |
bsl::enable_if< bsl::is_same < STRING_TYPE, bsl::string > ::value >::type | makeString (BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) string) |
void | swap (Json &other) |
JsonArray & | theArray () |
bool & | theBoolean () |
JsonNull & | theNull () |
JsonNumber & | theNumber () |
JsonObject & | theObject () |
operator JsonArray & () | |
operator bool & () | |
operator JsonNull & () | |
operator JsonNumber & () | |
operator JsonObject & () | |
Json & | operator[] (const bsl::string_view &key) |
Json & | operator[] (bsl::size_t index) |
int | asInt (int *result) const |
int | asInt64 (bsls::Types::Int64 *result) const |
int | asUint (unsigned int *result) const |
int | asUint64 (bsls::Types::Uint64 *result) const |
float | asFloat () const |
double | asDouble () const |
bdldfp::Decimal64 | asDecimal64 () const |
int | asDecimal64Exact (bdldfp::Decimal64 *result) const |
bool | isArray () const |
bool | isBoolean () const |
bool | isNull () const |
bool | isNumber () const |
bool | isObject () const |
bool | isString () const |
const JsonArray & | theArray () const |
const bool & | theBoolean () const |
const JsonNull & | theNull () const |
const JsonNumber & | theNumber () const |
const JsonObject & | theObject () const |
const bsl::string & | theString () const |
JsonType::Enum | type () const BSLS_KEYWORD_NOEXCEPT |
const Json & | operator[] (const bsl::string_view &key) const |
const Json & | operator[] (bsl::size_t index) const |
operator const JsonArray & () const | |
operator const bool & () const | |
operator const JsonNull & () const | |
operator const JsonNumber & () const | |
operator const JsonObject & () const | |
operator const bsl::string & () const | |
bsl::size_t | size () const |
bslma::Allocator * | allocator () const BSLS_KEYWORD_NOEXCEPT |
bsl::ostream & | print (bsl::ostream &stream, int level=0, int spacesPerLevel=4) const |
Friends | |
bool | operator== (const Json &, const Json &) |
bool | operator!= (const Json &, const Json &) |
template<class HASHALG > | |
void | hashAppend (HASHALG &, const Json &) |
void | swap (Json &, Json &) |
This type is designed to be a thin wrapper around a variant of the possible JSON types, using a BDE-style variant interface.
bdljsn::Json::Json | ( | ) |
bdljsn::Json::Json | ( | bslma::Allocator * | basicAllocator | ) | [explicit] |
bdljsn::Json::Json | ( | const Json & | original, | |
bslma::Allocator * | basicAllocator = 0 | |||
) |
Create a Json
object having the same value as the specified original
. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the currently installed default allocator is used to supply memory.
bdljsn::Json::Json | ( | bslmf::MovableRef< Json > | original | ) |
Create a Json
object having the same value as the specified original
object by moving (in constant time) the contents of original
to the new JsonObject
. The allocator associated with original
is propagated for use in the newly-created Json
object. original
is left in a valid but unspecified state.
bdljsn::Json::Json | ( | bslmf::MovableRef< Json > | original, | |
bslma::Allocator * | basicAllocator | |||
) |
Create a Json
object having the same value as the specified original
. Use the specified basicAllocator
to supply memory.
bdljsn::Json::Json | ( | const JsonArray & | array, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | bslmf::MovableRef< JsonArray > | array, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
Create a Json
object having the type JsonArray
and the same value as the specified array
object by moving (in constant time) the contents of array
to the new Json
object. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the allocator associated with array
is propagated for use in the newly-created Json
object. array
is left in a valid but unspecified state.
bdljsn::Json::Json | ( | bool | boolean, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
Create a Json
object having the type bool
and the same value as the specified boolean
. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the currently installed default allocator is used to supply memory.
bdljsn::Json::Json | ( | const JsonNull & | null, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | float | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | double | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | bdldfp::Decimal64 | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | int | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | unsigned int | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | bsls::Types::Int64 | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | bsls::Types::Uint64 | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | const JsonNumber & | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
Create a Json
object having the type JsonNumber
and the same value as the specified number
. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the currently installed default allocator is used to supply memory.
bdljsn::Json::Json | ( | bslmf::MovableRef< JsonNumber > | number, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
Create a Json
object having the type JsonNumber
and the same value as the specified number
object by moving (in constant time) the contents of number
to the new Json
object. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the allocator associated with number
is propagated for use in the newly-created Json
object. number
is left in a valid but unspecified state.
bdljsn::Json::Json | ( | const JsonObject & | object, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
Create a Json
object having the type JsonObject
and the same value as the specified object
. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the currently installed default allocator is used to supply memory.
bdljsn::Json::Json | ( | bslmf::MovableRef< JsonObject > | object, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
Create a Json
object having the type JsonObject
and the same value as the specified object
by moving (in constant time) the contents of object
to the new Json
object. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the allocator associated with object
is propagated for use in the newly-created Json
object. object
is left in a valid but unspecified state.
bdljsn::Json::Json | ( | const char * | string, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
bdljsn::Json::Json | ( | const bsl::string_view & | string, | |
bslma::Allocator * | basicAllocator = 0 | |||
) | [explicit] |
Create a Json
object having the type bsl::string
and the same value as the specified string
. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the currently installed default allocator is used to supply memory. The behavior is undefined unless string
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
bdljsn::Json::Json | ( | BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) | string, | |
bslma::Allocator * | basicAllocator = 0 , |
|||
typename bsl::enable_if< bsl::is_same< STRING_TYPE, bsl::string >::value >::type * | = 0 | |||
) | [explicit] |
Create a Json
object having the type bsl::string
and the same value as the specified string
by moving (in constant time) the contents of string
to the new Json
object. Optionally specify the basicAllocator
used to supply memory. If basicAllocator
is not specified, the allocator associated with string
is propagated for use in the newly-created Json
object. string
is left in a valid but unspecified state. This function does not participate in overload resolution unless the specified STRING_TYPE
is bsl::string
. The behavior is undefined unless string
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
bdljsn::Json::BSLMF_NESTED_TRAIT_DECLARATION | ( | Json | , | |
bslma::UsesBslmaAllocator | ||||
) |
bdljsn::Json::BSLMF_NESTED_TRAIT_DECLARATION | ( | Json | , | |
bslmf::IsBitwiseMoveable | ||||
) |
bdljsn::Json::BSLMF_NESTED_TRAIT_DECLARATION | ( | Json | , | |
bdlb::HasPrintMethod | ||||
) |
Assign to this object the value of the specified rhs
object, and return a reference providing modifiable access to this object. The value currently held by this variant is destroyed if that value's type is not the same as the type held by the rhs
object.
Json& bdljsn::Json::operator= | ( | bslmf::MovableRef< Json > | rhs | ) |
Assign to this object the value of the specified rhs
object, and return a reference providing modifiable access to this object. The contents of rhs
are moved (in constant time) to this Json
object if allocator() == rhs.allocator()
; otherwise they are copied. rhs
is left in a valid but unspecified state.
Json& bdljsn::Json::operator= | ( | float | rhs | ) |
Json& bdljsn::Json::operator= | ( | double | rhs | ) |
Json& bdljsn::Json::operator= | ( | bdldfp::Decimal64 | rhs | ) |
Json& bdljsn::Json::operator= | ( | int | rhs | ) |
Json& bdljsn::Json::operator= | ( | unsigned int | rhs | ) |
Json& bdljsn::Json::operator= | ( | bsls::Types::Int64 | rhs | ) |
Json& bdljsn::Json::operator= | ( | bsls::Types::Uint64 | rhs | ) |
Json& bdljsn::Json::operator= | ( | const JsonNumber & | rhs | ) |
Assign to this object a value of type JsonNumber
initialized from the specified rhs
, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not JsonNumber
.
Json& bdljsn::Json::operator= | ( | bslmf::MovableRef< JsonNumber > | rhs | ) |
Assign to this object the value of the specified rhs
object, and return a reference providing modifiable access to this object. The contents of rhs
are moved (in constant time) to this Json
object if allocator() == rhs.allocator()
; otherwise, they are copied. rhs
is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not JsonNumber
.
Json& bdljsn::Json::operator= | ( | const char * | rhs | ) |
Json& bdljsn::Json::operator= | ( | const bsl::string_view & | rhs | ) |
Assign to this object a value of type bsl::string
initialized from the specified rhs
, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not bsl::string
. The behavior is undefined unless rhs
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
bsl::enable_if<bsl::is_same<STRING_TYPE, bsl::string>::value, Json>::type& bdljsn::Json::operator= | ( | BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) | rhs | ) |
Assign to this object the value of the specified rhs
object, and return a reference providing modifiable access to this object. The contents of rhs
are moved (in constant time) to this Json
object if allocator() == rhs.allocator()
; otherwise, they are copied. rhs
is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not bsl::string
. This function does not participate in overload resolution unless the specified STRING_TYPE
is bsl::string
. The behavior is undefined unless rhs
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
Json& bdljsn::Json::operator= | ( | bool | rhs | ) |
Assign to this object a value of type bool
initialized from the specified rhs
, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not bsl::string
.
Json& bdljsn::Json::operator= | ( | const JsonObject & | rhs | ) |
Assign to this object a value of type JsonObject
initialized from the specified rhs
, and return a reference providing modifiable access to this object. The value currently held by this object (if any) is destroyed if that value's type is not JsonObject
.
Json& bdljsn::Json::operator= | ( | bslmf::MovableRef< JsonObject > | rhs | ) |
Assign to this object the value of the specified rhs
object, and return a reference providing modifiable access to this object. The contents of rhs
are moved (in constant time) to this Json
object if allocator() == rhs.allocator()
; otherwise, they are copied. rhs
is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not JsonObject
.
Json& bdljsn::Json::operator= | ( | bslmf::MovableRef< JsonArray > | rhs | ) |
Assign to this object the value of the specified rhs
object, and return a reference providing modifiable access to this object. The contents of rhs
are moved (in constant time) to this Json
object if allocator() == rhs.allocator()
; otherwise, they are copied. rhs
is left in a valid but unspecified state. The value currently held by this object (if any) is destroyed if that value's type is not JsonArray
.
Json& bdljsn::Json::operator= | ( | bslmf::MovableRef< JsonNull > | ) |
JsonArray& bdljsn::Json::makeArray | ( | ) |
JsonArray& bdljsn::Json::makeArray | ( | bslmf::MovableRef< JsonArray > | array | ) |
Create an instance of type JsonArray
in this object, using the allocator currently held by this object to supply memory, and return a reference providing modifiable access to the created instance. Optionally specify array
to initialize the JsonArray
created. This method first destroys the current value held by this object (even if the type currently held is JsonArray
).
bool& bdljsn::Json::makeBoolean | ( | ) |
bool& bdljsn::Json::makeBoolean | ( | bool | boolean | ) |
Create an instance of type bool
in this object and return a reference providing modifiable access to the created instance. Optionally specify boolean
to initialize the bool
created. This method first destroys the current value held by this object.
void bdljsn::Json::makeNull | ( | ) |
Create an instance of type JsonNull
in this object. This method first destroys the current value held by this object.
JsonNumber& bdljsn::Json::makeNumber | ( | ) |
JsonNumber& bdljsn::Json::makeNumber | ( | const JsonNumber & | number | ) |
JsonNumber& bdljsn::Json::makeNumber | ( | bslmf::MovableRef< JsonNumber > | number | ) |
Create an instance of type JsonNumber
in this object, using the allocator currently held by this object to supply memory, and return a reference providing modifiable access to the created instance. Optionally specify number
to initialize the JsonNumber
created. This method first destroys the current value held by this object (even if the type currently held is JsonNumber
).
JsonObject& bdljsn::Json::makeObject | ( | ) |
JsonObject& bdljsn::Json::makeObject | ( | const JsonObject & | object | ) |
JsonObject& bdljsn::Json::makeObject | ( | bslmf::MovableRef< JsonObject > | object | ) |
Create an instance of type JsonObject
in this object, using the allocator currently held by this object to supply memory, and return a reference providing modifiable access to the created instance. Optionally specify object
to initialize the JsonObject
created. This method first destroys the current value held by this object (even if the type currently held is JsonObject
).
void bdljsn::Json::makeString | ( | const char * | string | ) |
void bdljsn::Json::makeString | ( | const bsl::string_view & | string | ) |
Create an instance of type bsl::string
in this object, using the allocator currently held by this object to supply memory. Optionally specify string
to initialize the bsl::string
created. This method first destroys the current value held by this object (even if the type currently held is bsl::string
). The behavior is undefined unless string
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
bsl::enable_if< bsl::is_same<STRING_TYPE, bsl::string>::value>::type bdljsn::Json::makeString | ( | BSLMF_MOVABLEREF_DEDUCE(STRING_TYPE) | string | ) |
Create an instance of type bsl::string
in this object, using the allocator currently held by this object to supply memory. Optionally specify string
to initialize the bsl::string
created. This method first destroys the current value held by this object (even if the type currently held is bsl::string
). This function does not participate in overload resolution unless the specified STRING_TYPE
is bsl::string
. The behavior is undefined unless string
is valid UTF-8 (see bdlde::Utf8Util::isValid
).
void bdljsn::Json::swap | ( | Json & | other | ) |
Exchange the value of this with that of the specified other
. If an exception is thrown, both objects are left in valid but unspecified states. This operation guarantees O[1] complexity. The behavior is undefined unless this object was created with the same allocator as other
.
JsonArray& bdljsn::Json::theArray | ( | ) |
bool& bdljsn::Json::theBoolean | ( | ) |
Return a reference providing modifiable access to the value of type boolean
held by this object. The behavior is undefined unless isBoolean()
returns true.
JsonNull& bdljsn::Json::theNull | ( | ) |
JsonNumber& bdljsn::Json::theNumber | ( | ) |
Return a reference providing modifiable access to the value of type JsonNumber
held by this object. The behavior is undefined unless isNumber()
returns true.
JsonObject& bdljsn::Json::theObject | ( | ) |
Return a reference providing modifiable access to the value of type JsonObject
held by this object. The behavior is undefined unless isObject()
returns true.
bdljsn::Json::operator JsonArray & | ( | ) | [explicit] |
bdljsn::Json::operator bool & | ( | ) | [explicit] |
Return a reference providing modifiable access to the value of type boolean
held by this object. The behavior is undefined unless isBoolean()
returns true.
bdljsn::Json::operator JsonNull & | ( | ) | [explicit] |
bdljsn::Json::operator JsonNumber & | ( | ) | [explicit] |
Return a reference providing modifiable access to the value of type JsonNumber
held by this object. The behavior is undefined unless isNumber()
returns true.
bdljsn::Json::operator JsonObject & | ( | ) | [explicit] |
Return a reference providing modifiable access to the value of type JsonObject
held by this object. The behavior is undefined unless isObject()
returns true.
Json& bdljsn::Json::operator[] | ( | const bsl::string_view & | key | ) |
Return a reference providing modifiable access to the Json
object assicated with the specified key
in the JsonObject
held by this object; if the JsonObject
does not already contain a Json
object assicated with key
, first insert a new default-constructed Json
object assicated with key
. The behavior is undefined unless isObject()
returns true.
Json& bdljsn::Json::operator[] | ( | bsl::size_t | index | ) |
Return a reference providing modifiable access to the element at the specified index
in the JsonArray
held by this object. The behavior is undefined unless isArray()
returns true and index < theArray().size()
.
int bdljsn::Json::asInt | ( | int * | result | ) | const |
int bdljsn::Json::asInt64 | ( | bsls::Types::Int64 * | result | ) | const |
int bdljsn::Json::asUint | ( | unsigned int * | result | ) | const |
int bdljsn::Json::asUint64 | ( | bsls::Types::Uint64 * | result | ) | const |
Load into the specified result
the integer value of the value of type JsonNumber
held by this object. Return 0 on success, JsonNumber::k_OVERFLOW
if value
is larger than can be represented by result
, JsonNumber::k_UNDERFLOW
if value
is smaller than can be represented by result
, and JsonNumber::k_NOT_INTEGRAL
if value
is not an integral number (i.e., there is a fractional part). For underflow, result
will be loaded with the minimum representable value, for overflow, result
will be loaded with the maximum representable value, for non-integral values result
will be loaded with the integer part of value
(trucating the value to the nearest integer). If the result is not an integer and also either overflows or underflows, it is treated as an overflow or underflow (respectively). Note that this operation returns a status value (unlike similar floating point conversions) because typically it is an error if a conversion to an integer results in an inexact value. The behavior is undefined unless isNumber()
returns true.
float bdljsn::Json::asFloat | ( | ) | const |
double bdljsn::Json::asDouble | ( | ) | const |
bdldfp::Decimal64 bdljsn::Json::asDecimal64 | ( | ) | const |
Return the closest floating point representation to the value of the type JsonNumber
held by this object. If this number is outside the representable range, return +INF or -INF (as appropriate). The behavior is undefined unless isNumber()
returns true. BDE_VERIFY pragma: +FABC01
int bdljsn::Json::asDecimal64Exact | ( | bdldfp::Decimal64 * | result | ) | const |
Load the specified result
with the closest floating point representation to the value of type JsonNumber
held by this object, even if a non-zero status is returned. Return 0 if this number can be represented exactly, and return JsonNumber::k_INEXACT
if value
cannot be represented exactly. If this number is outside the representable range, load result
with +INF or -INF (as appropriate). A number can be represented exactly as a Decimal64
if, for the significand and exponent, abs(significand) <= 9,999,999,999,999,999
and '-398 <= exponent <= 369'. The behavior is undefined unless isNumber()
returns true;
bool bdljsn::Json::isArray | ( | ) | const |
Return true if the value held by this object is of type JsonArray
, and false otherwise.
bool bdljsn::Json::isBoolean | ( | ) | const |
Return true if the value held by this object is of type bool
, and false otherwise.
bool bdljsn::Json::isNull | ( | ) | const |
Return true if the value held by this object is of type JsonNull
, and false otherwise.
bool bdljsn::Json::isNumber | ( | ) | const |
Return true if the value held by this object is of type JsonNumber
, and false otherwise.
bool bdljsn::Json::isObject | ( | ) | const |
Return true if the value held by this object is of type JsonObject
, and false otherwise.
bool bdljsn::Json::isString | ( | ) | const |
Return true if the value held by this object is of type bsl::string
, and false otherwise.
const JsonArray& bdljsn::Json::theArray | ( | ) | const |
const bool& bdljsn::Json::theBoolean | ( | ) | const |
Return a reference providing non-modifiable access to the value of type boolean
held by this object. The behavior is undefined unless isBoolean()
returns true.
const JsonNull& bdljsn::Json::theNull | ( | ) | const |
const JsonNumber& bdljsn::Json::theNumber | ( | ) | const |
Return a reference providing non-modifiable access to the value of type JsonNumber
held by this object. The behavior is undefined unless isNumber()
returns true.
const JsonObject& bdljsn::Json::theObject | ( | ) | const |
Return a reference providing non-modifiable access to the value of type JsonObject
held by this object. The behavior is undefined unless isObject()
returns true.
const bsl::string& bdljsn::Json::theString | ( | ) | const |
Return a reference providing non-modifiable access to the value of type JsonString
held by this object. The behavior is undefined unless isString()
returns true.
JsonType::Enum bdljsn::Json::type | ( | ) | const |
Return the type of this Json
value.
const Json& bdljsn::Json::operator[] | ( | const bsl::string_view & | key | ) | const |
Return a reference providing non-modifiable access to the Json
object associated with the specified key
in this JsonObject
. The behavior is undefined unless key
is valid UTF-8 (see bdlde::Utf8Util::isValid
) and this JsonObject
already contains a Json
object assicated with key
.
const Json& bdljsn::Json::operator[] | ( | bsl::size_t | index | ) | const |
Return a reference providing non-modifiable access to the element at the specified index
in the JsonArray
held by this object. The behavior is undefined unless isArray()
returns true and index < theArray().size()
.
bdljsn::Json::operator const JsonArray & | ( | ) | const [explicit] |
bdljsn::Json::operator const bool & | ( | ) | const [explicit] |
Return a reference providing non-modifiable access to the value of type boolean
held by this object. The behavior is undefined unless isBoolean()
returns true.
bdljsn::Json::operator const JsonNull & | ( | ) | const [explicit] |
bdljsn::Json::operator const JsonNumber & | ( | ) | const [explicit] |
Return a reference providing non-modifiable access to the value of type JsonNumber
held by this object. The behavior is undefined unless isNumber()
returns true.
bdljsn::Json::operator const JsonObject & | ( | ) | const [explicit] |
Return a reference providing non-modifiable access to the value of type JsonObject
held by this object. The behavior is undefined unless isObject()
returns true.
bdljsn::Json::operator const bsl::string & | ( | ) | const [explicit] |
Return a reference providing non-modifiable access to the value of type JsonString
held by this object. The behavior is undefined unless isString()
returns true.
bsl::size_t bdljsn::Json::size | ( | ) | const |
Return the number of elements in the JsonObject
or JsonArray
held by this object. The behavior is undefined unless isArray() || isObject()
evaluates to true.
bslma::Allocator* bdljsn::Json::allocator | ( | ) | const |
Return the allocator used by this object to allocate memory.
bsl::ostream& bdljsn::Json::print | ( | bsl::ostream & | stream, | |
int | level = 0 , |
|||
int | spacesPerLevel = 4 | |||
) | const |
Write the value of this object to the specified output stream
in a human-readable format, and return a reference to stream
. Optionally specify an initial indentation level
, whose absolute value is incremented recursively for nested objects. If level
is specified, optionally specify spacesPerLevel
, whose absolute value indicates the number of spaces per indentation level for this and all of its nested objects. If level
is negative, suppress indentation of the first line. If spacesPerLevel
is negative, format the entire output on one line, suppressing all but the initial indentation (as governed by level
). If stream
is not valid on entry, this operation has no effect. Note that this human-readable format is not fully specified, and can change without notice.
Return true
if the specified lhs
and rhs
objects have the same value, and false
otherwise. Two Json
objects lhs
and rhs
have the same value if they hold objects of the same type, and those objects have the same value.
Return false
if the specified lhs
and rhs
objects have the same value, and true
otherwise. Two Json
objects lhs
and rhs
have the same value if they hold objects of the same type, and those objects have the same value.
void hashAppend | ( | HASHALG & | , | |
const Json & | ||||
) | [friend] |
Invoke the specified hashAlg
on the attributes of the specified object
.