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, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::push_back |
( |
const typename object_t::value_type & |
val | ) |
|
|
inline |
add an object to an object
Inserts the given element val to the JSON object. If the function is called on a JSON null value, an empty object is created before inserting val.
- Parameters
-
[in] | val | the value to add to the JSON object |
- Exceptions
-
type_error.308 | when called on a type other than JSON object or null; example: "cannot use push_back() with number" |
@complexity Logarithmic in the size of the container, O(log(size()
)).
@liveexample{The example shows how push_back()
and +=
can be used to add elements to a JSON object. Note how the null
value was silently converted to a JSON object.,push_back__object_t__value}
- Since
- version 1.0.0
Definition at line 23237 of file json.hpp.
23238 {
23239
23241 {
23242 JSON_THROW(type_error::create(308,
"cannot use push_back() with " + std::string(
type_name()), *
this));
23243 }
23244
23245
23247 {
23251 }
23252
23253
23254 auto res =
m_value.object->insert(val);
23255 set_parent(res.first->second);
23256 }
void assert_invariant(bool check_parents=true) const noexcept
checks the class invariants
constexpr bool is_object() const noexcept
return whether value is an object
json_value m_value
the value of the current element
JSON_HEDLEY_RETURNS_NON_NULL const char * type_name() const noexcept
return the type as string
constexpr bool is_null() const noexcept
return whether value is null
@ object
object (unordered set of name/value pairs)