! @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
| 19950 | @since version 3.0.0 |
| 19951 | */ |
| 19952 | void update(const_reference j) |
| 19953 | { |
| 19954 | // implicitly convert null value to an empty object |
| 19955 | if (is_null()) |
| 19956 | { |
| 19957 | m_type = value_t::object; |
| 19958 | m_value.object = create<object_t>(); |
| 19959 | assert_invariant(); |
| 19960 | } |
| 19961 | |
| 19962 | if (JSON_HEDLEY_UNLIKELY(not is_object())) |
| 19963 | { |
| 19964 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()))); |
| 19965 | } |
| 19966 | if (JSON_HEDLEY_UNLIKELY(not j.is_object())) |
| 19967 | { |
| 19968 | JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()))); |
| 19969 | } |
| 19970 | |
| 19971 | for (auto it = j.cbegin(); it != j.cend(); ++it) |
| 19972 | { |
| 19973 | m_value.object->operator[](it.key()) = it.value(); |
| 19974 | } |
| 19975 | } |
| 19976 | |
| 19977 | /*! |
| 19978 | @brief updates a JSON object from another object, overwriting existing keys |
nothing calls this directly
no test coverage detected