JSON for Modern C++ 3.7.1

accept
accept
allocator_type
array
array_t
at
at
at
at
at
at
back
back
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
boolean_t
cbegin
cend
clear
const_iterator
const_pointer
const_reference
const_reverse_iterator
contains
contains
count
crbegin
crend
detail::external_constructor
diff
difference_type
dump
emplace
emplace_back
empty
end
end
erase
erase
erase
erase
error_handler_t
exception
find
find
flatten
from_bson
from_bson
from_cbor
from_cbor
from_msgpack
from_msgpack
from_ubjson
from_ubjson
front
front
get
get
get
get
get
get
get_allocator
get_ptr
get_ptr
get_ref
get_ref
get_to
get_to
initializer_list_t
input_format_t
insert
insert
insert
insert
insert
insert
insert_iterator
invalid_iterator
is_array
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_number_unsigned
is_object
is_primitive
is_string
is_structured
items
items
iterator
iterator_wrapper
iterator_wrapper
json_pointer
json_sax_t
json_serializer
max_size
merge_patch
meta
number_float_t
number_integer_t
number_unsigned_t
object
object_comparator_t
object_t
operator value_t
operator ValueType
operator!=
operator!=
operator!=
operator+=
operator+=
operator+=
operator+=
operator<
operator<
operator<
operator<<
operator<<
operator<=
operator<=
operator<=
operator=
operator==
operator==
operator==
operator>
operator>
operator>
operator>=
operator>=
operator>=
operator>>
operator>>
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
other_error
out_of_range
parse
parse
parse_error
parse_event_t
parser_callback_t
patch
pointer
push_back
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
reverse_iterator
sax_parse
sax_parse
size
size_type
string_t
swap
swap
swap
swap
to_bson
to_bson
to_bson
to_cbor
to_cbor
to_cbor
to_msgpack
to_msgpack
to_msgpack
to_ubjson
to_ubjson
to_ubjson
type
type_error
type_name
unflatten
update
update
value
value
value
value
value_t
value_type
~basic_json
| ## ◆ from_bson() [1/2] template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer> template<typename A1 , typename A2 , detail::enable_if_t< std::is_constructible< detail::input_adapter, A1, A2 >::value, int > = 0>
static basic_json nlohmann::basic_json::from_bson | ( | A1 && | a1,
|  | A2 && | a2,
|  | const bool | strict = `true`,
|  | const bool | allow_exceptions = `true`
| ) |  |
| inline static
Deserializes a given input i to a JSON value using the BSON (Binary JSON) serialization format. The library maps BSON record types to JSON value types as follows:
BSON type | BSON marker byte | JSON value type
--- | --- | ---
double | 0x01 | number_float
string | 0x02 | string
document | 0x03 | object
array | 0x04 | array
binary | 0x05 | still unsupported
undefined | 0x06 | still unsupported
ObjectId | 0x07 | still unsupported
boolean | 0x08 | boolean
UTC Date-Time | 0x09 | still unsupported
null | 0x0A | null
Regular Expr. | 0x0B | still unsupported
DB Pointer | 0x0C | still unsupported
JavaScript Code | 0x0D | still unsupported
Symbol | 0x0E | still unsupported
JavaScript Code | 0x0F | still unsupported
int32 | 0x10 | number_integer
Timestamp | 0x11 | still unsupported
128-bit decimal float | 0x13 | still unsupported
Max Key | 0x7F | still unsupported
Min Key | 0xFF | still unsupported
  Warning The mapping is incomplete. The unsupported mappings are indicated in the table above. Parameters
  [in] | i | an input in BSON format convertible to an input adapter
  [in] | strict | whether to expect the input to be consumed until EOF (true by default)
  [in] | allow_exceptions | whether to throw exceptions in case of a parse error (optional, true by default)
  Returns deserialized JSON value; in case of a parse error and allow_exceptions set to `false`, the return value will be value_t::discarded. Exceptions
  parse_error.114 | if an unsupported BSON record type is encountered
  Complexity Linear in the size of the input i. Example The example shows the deserialization of a byte vector in BSON format to a JSON value. 1 #include <iostream> 2 #include <iomanip> 3 #include <nlohmann/json.hpp> 4 5 using json = nlohmann::json; 6 7 int main() 8 { 9 // create byte vector 10 std::vector<uint8_t> v = {0x1b, 0x00, 0x00, 0x00, 0x08, 0x63, 0x6f, 0x6d, 11 0x70, 0x61, 0x63, 0x74, 0x00, 0x01, 0x10, 0x73, 12 0x63, 0x68, 0x65, 0x6d, 0x61, 0x00, 0x00, 0x00, 13 0x00, 0x00, 0x00 14 }; 15 16 // deserialize it with BSON 17 json j = json::from_bson(v); 18 19 // print the deserialized JSON value 20 std::cout << std::setw(2) << j << std::endl; 21 } Output (play with this example online):
      {
        "compact": true,
        "schema": 0
      }
  The example code above can be translated with
      g++ -std=c++11 -Isingle_include doc/examples/from_bson.cpp -o from_bson
See also http://bsonspec.org/spec.html to_bson(const basic_json&) for the analogous serialization from_cbor(detail::input_adapter&&, const bool, const bool) for the related CBOR format from_msgpack(detail::input_adapter&&, const bool, const bool) for the related MessagePack format from_ubjson(detail::input_adapter&&, const bool, const bool) for the related UBJSON format Definition at line 21780 of file json.hpp.

nlohmann::basic_json::from_bson
static basic_json from_bson(detail::input_adapter &&i, const bool strict=true, const bool allow_exceptions=true)
Create a JSON value from an input in BSON format.
Definition: json.hpp:21764
nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:2445