[#BloombergLP-bdljsn-Json] = xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bdljsn.adoc[bdljsn]::Json :relfileprefix: ../../ :mrdocs: This type is designed to be a thin wrapper around a variant of the possible JSON types, using a BDE‐style variant interface. == Synopsis Declared in `<bdljsn_json.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- class Json; ---- == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdljsn/Json/2constructor-0b3.adoc[`Json`] [.small]#[constructor]# | Constructors | xref:BloombergLP/bdljsn/Json/operator_assign-06.adoc[`operator=`] | Assignment operators | xref:BloombergLP/bdljsn/Json/allocator.adoc[`allocator`] | Return the allocator used by this object to allocate memory. | xref:BloombergLP/bdljsn/Json/asDecimal64.adoc[`asDecimal64`] | Same as the related overload above for `asDecimal64`. | xref:BloombergLP/bdljsn/Json/asDecimal64Exact.adoc[`asDecimal64Exact`] | 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`; | xref:BloombergLP/bdljsn/Json/asDouble.adoc[`asDouble`] | Same as the related overload above for `asDouble`. | xref:BloombergLP/bdljsn/Json/asFloat.adoc[`asFloat`] | 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. | xref:BloombergLP/bdljsn/Json/asInt.adoc[`asInt`] | Same as the related overload above for `asInt`. | xref:BloombergLP/bdljsn/Json/asInt64.adoc[`asInt64`] | Same as the related overload above for `asInt64`. | xref:BloombergLP/bdljsn/Json/asLong.adoc[`asLong`] | Same as the overload taking `int`. | xref:BloombergLP/bdljsn/Json/asLonglong.adoc[`asLonglong`] | Same as the related overload above for `asLonglong`. | xref:BloombergLP/bdljsn/Json/asShort.adoc[`asShort`] | 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` (truncating 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. Also note that on all supported platforms `bsls::Types::Int64` and `bsls::Types::Uint64` are, respectively, aliases for `long long` and `unsigned long long`. | xref:BloombergLP/bdljsn/Json/asUint.adoc[`asUint`] | Same as the related overload above for `asUint`. | xref:BloombergLP/bdljsn/Json/asUint64.adoc[`asUint64`] | Same as the related overload above for `asUint64`. | xref:BloombergLP/bdljsn/Json/asUlong.adoc[`asUlong`] | Same as the overload taking `unsigned int`. | xref:BloombergLP/bdljsn/Json/asUlonglong.adoc[`asUlonglong`] | Same as the overload taking `long long`. | xref:BloombergLP/bdljsn/Json/asUshort.adoc[`asUshort`] | Same as the related overload above for `asUshort`. | xref:BloombergLP/bdljsn/Json/contains.adoc[`contains`] | Return `true` if the `JsonObject` held by this `Json` object contains a member whose key is equivalent to the specified `key`, and return `false` otherwise. The behavior is undefined unless `true == isObject()`. | xref:BloombergLP/bdljsn/Json/insert-09.adoc[`insert`] | `insert` overloads | xref:BloombergLP/bdljsn/Json/isArray.adoc[`isArray`] | Return true if the value held by this object is of type `JsonArray`, and false otherwise. | xref:BloombergLP/bdljsn/Json/isBoolean.adoc[`isBoolean`] | Return true if the value held by this object is of type `bool`, and false otherwise. | xref:BloombergLP/bdljsn/Json/isNull.adoc[`isNull`] | Return true if the value held by this object is of type `JsonNull`, and false otherwise. | xref:BloombergLP/bdljsn/Json/isNumber.adoc[`isNumber`] | Return true if the value held by this object is of type `JsonNumber`, and false otherwise. | xref:BloombergLP/bdljsn/Json/isObject.adoc[`isObject`] | Return true if the value held by this object is of type `JsonObject`, and false otherwise. | xref:BloombergLP/bdljsn/Json/isString.adoc[`isString`] | Return true if the value held by this object is of type `bsl::string`, and false otherwise. | xref:BloombergLP/bdljsn/Json/makeArray-01.adoc[`makeArray`] | `makeArray` overloads | xref:BloombergLP/bdljsn/Json/makeBoolean-0e.adoc[`makeBoolean`] | `makeBoolean` overloads | xref:BloombergLP/bdljsn/Json/makeNull.adoc[`makeNull`] | Create an instance of type `JsonNull` in this object. This method first destroys the current value held by this object. | xref:BloombergLP/bdljsn/Json/makeNumber-0c.adoc[`makeNumber`] | `makeNumber` overloads | xref:BloombergLP/bdljsn/Json/makeObject-01.adoc[`makeObject`] | `makeObject` overloads | xref:BloombergLP/bdljsn/Json/makeString-02.adoc[`makeString`] | `makeString` overloads | xref:BloombergLP/bdljsn/Json/operator_subs-0f.adoc[`operator[]`] | Subscript operators | xref:BloombergLP/bdljsn/Json/print.adoc[`print`] | 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. | xref:BloombergLP/bdljsn/Json/pushBack-0ce.adoc[`pushBack`] | `pushBack` overloads | xref:BloombergLP/bdljsn/Json/size.adoc[`size`] | Return the number of elements in the `JsonObject` or `JsonArray` held by this object. The behavior is undefined unless `isArray() || isObject()` evaluates to true. | xref:BloombergLP/bdljsn/Json/swap.adoc[`swap`] | 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`. | xref:BloombergLP/bdljsn/Json/theArray-0f.adoc[`theArray`] | `theArray` overloads | xref:BloombergLP/bdljsn/Json/theBoolean-0f.adoc[`theBoolean`] | `theBoolean` overloads | xref:BloombergLP/bdljsn/Json/theNull-0c.adoc[`theNull`] | `theNull` overloads | xref:BloombergLP/bdljsn/Json/theNumber-01.adoc[`theNumber`] | `theNumber` overloads | xref:BloombergLP/bdljsn/Json/theObject-08a.adoc[`theObject`] | `theObject` overloads | xref:BloombergLP/bdljsn/Json/theString.adoc[`theString`] | 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. | xref:BloombergLP/bdljsn/Json/type.adoc[`type`] | Return the type of this `Json` value. | xref:BloombergLP/bdljsn/Json/visit-0a.adoc[`visit`] | `visit` overloads | xref:BloombergLP/bdljsn/Json/2conversion-05d0.adoc[`operator BloombergLP::bslmf::NestedTraitDeclaration<Json, HasPrintMethod>`] | Declare nested type traits for this type. | xref:BloombergLP/bdljsn/Json/2conversion-0def.adoc[`operator JsonArray&`] | Return a reference providing modifiable access to the value of type `JsonArray` held by this object. The behavior is undefined unless `isArray()` returns true. | xref:BloombergLP/bdljsn/Json/2conversion-0a9.adoc[`operator JsonNull&`] | Return a reference providing modifiable access to the value of type `JsonNull` held by this object. The behavior is undefined unless `isNull()` returns true. | xref:BloombergLP/bdljsn/Json/2conversion-0e.adoc[`operator JsonNumber&`] | Return a reference providing modifiable access to the value of type `JsonNumber` held by this object. The behavior is undefined unless `isNumber()` returns true. | xref:BloombergLP/bdljsn/Json/2conversion-08.adoc[`operator JsonObject&`] | Return a reference providing modifiable access to the value of type `JsonObject` held by this object. The behavior is undefined unless `isObject()` returns true. | xref:BloombergLP/bdljsn/Json/2conversion-01.adoc[`operator bool&`] | Return a reference providing modifiable access to the value of type `boolean` held by this object. The behavior is undefined unless `isBoolean()` returns true. | xref:BloombergLP/bdljsn/Json/2conversion-04.adoc[`operator JsonArray const&`] | Return a reference providing non‐modifiable access to the value of type `JsonArray` held by this object. The behavior is undefined unless `isArray()` returns true. | xref:BloombergLP/bdljsn/Json/2conversion-0aa.adoc[`operator JsonNull const&`] | Return a reference providing non‐modifiable access to the value of type `JsonNull` held by this object. The behavior is undefined unless `isNull()` returns true. | xref:BloombergLP/bdljsn/Json/2conversion-0de6.adoc[`operator JsonNumber 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. | xref:BloombergLP/bdljsn/Json/2conversion-05d7.adoc[`operator JsonObject 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. | xref:BloombergLP/bdljsn/Json/2conversion-0b.adoc[`operator bool 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. | xref:BloombergLP/bdljsn/Json/2conversion-00.adoc[`operator bsl::string 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. |=== == Friends [cols="1,4"] |=== | Name| Description | `xref:BloombergLP/bdljsn/swap-04.adoc[BloombergLP::bdljsn::swap]` | Exchange the value of the specified `a` `Json` object with that of the specified `b` `Json` object. 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 `a` was created with the same allocator as `b`. | `xref:BloombergLP/bdljsn/operator_not_eq-0b5.adoc[BloombergLP::bdljsn::operator!=]` | 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. | `xref:BloombergLP/bdljsn/operator_eq-0d2.adoc[BloombergLP::bdljsn::operator==]` | 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. |=== == Non-Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bdljsn/operator_not_eq-00f.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-014.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-015.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-04.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-053.adoc[`operator!=`] | Return `true` if the specified `lhs` and `rhs` do not have the same value. | xref:BloombergLP/bdljsn/operator_not_eq-05b.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-05f.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-076.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-078.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-087.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-09.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-0a.adoc[`operator!=`] | Process the specified `array` during visitation of a `bdljsn::Json` object. | xref:BloombergLP/bdljsn/operator_not_eq-0c0.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-0d5.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-0ee.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_not_eq-0f5.adoc[`operator!=`] | Same as the related overload above for `operator!=`. | xref:BloombergLP/bdljsn/operator_json.adoc[`operator""_json`] | Return a `bdljsn::Json` object having the value of the JSON described in the specified `text` of the specified `numBytes`. If `text` is not a valid JSON document then invoke the currently installed `bsls::Assert` failure handler. | xref:BloombergLP/bdljsn/operator_eq-025.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-02a.adoc[`operator==`] | Process the specified `object` during visitation of a `bdljsn::Json` object. | xref:BloombergLP/bdljsn/operator_eq-03f.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-040.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-0482.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-05f0.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-060.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-071.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-077.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-0844.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-089.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-0b.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-0c8.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-0cd.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-0e1.adoc[`operator==`] | Same as the related overload above for `operator==`. | xref:BloombergLP/bdljsn/operator_eq-0f1.adoc[`operator==`] | Process the specified `array` during visitation of a `bdljsn::Json` object. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#