! @brief updates a JSON object from another object, overwriting existing keys Inserts all values from JSON object @a j and overwrites existing keys. @param[in] j JSON object to read values from @throw type_error.312 if called on JSON values other than objects; example: `"cannot use update() with string"` @complexity O(N*log(size() + N)), where N is the number of elemen
| 23499 | @since version 3.0.0 |
| 23500 | */ |
| 23501 | void update(const_reference j) |
| 23502 | { |
| 23503 | // implicitly convert null value to an empty object |
| 23504 | if (is_null()) |
| 23505 | { |
| 23506 | m_type = value_t::object; |
| 23507 | m_value.object = create<object_t>(); |
| 23508 | assert_invariant(); |
| 23509 | } |
| 23510 | |
| 23511 | if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| 23512 | { |
| 23513 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this)); |
| 23514 | } |
| 23515 | if (JSON_HEDLEY_UNLIKELY(!j.is_object())) |
| 23516 | { |
| 23517 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this)); |
| 23518 | } |
| 23519 | |
| 23520 | for (auto it = j.cbegin(); it != j.cend(); ++it) |
| 23521 | { |
| 23522 | m_value.object->operator[](it.key()) = it.value(); |
| 23523 | #if JSON_DIAGNOSTICS |
| 23524 | m_value.object->operator[](it.key()).m_parent = this; |
| 23525 | #endif |
| 23526 | } |
| 23527 | } |
| 23528 | |
| 23529 | /*! |
| 23530 | @brief updates a JSON object from another object, overwriting existing keys |