! @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
| 5998 | @since version 3.0.0 |
| 5999 | */ |
| 6000 | void update(const_reference j) |
| 6001 | { |
| 6002 | // implicitly convert null value to an empty object |
| 6003 | if (is_null()) |
| 6004 | { |
| 6005 | m_type = value_t::object; |
| 6006 | m_value.object = create<object_t>(); |
| 6007 | assert_invariant(); |
| 6008 | } |
| 6009 | |
| 6010 | if (JSON_HEDLEY_UNLIKELY(!is_object())) |
| 6011 | { |
| 6012 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this)); |
| 6013 | } |
| 6014 | if (JSON_HEDLEY_UNLIKELY(!j.is_object())) |
| 6015 | { |
| 6016 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this)); |
| 6017 | } |
| 6018 | |
| 6019 | for (auto it = j.cbegin(); it != j.cend(); ++it) |
| 6020 | { |
| 6021 | m_value.object->operator[](it.key()) = it.value(); |
| 6022 | #if JSON_DIAGNOSTICS |
| 6023 | m_value.object->operator[](it.key()).m_parent = this; |
| 6024 | #endif |
| 6025 | } |
| 6026 | } |
| 6027 | |
| 6028 | /*! |
| 6029 | @brief updates a JSON object from another object, overwriting existing keys |