1# basic_json::update 2 3```cpp 4// (1) 5void update(const_reference j); 6 7// (2) 8void update(const_iterator first, const_iterator last); 9``` 10 111. Inserts all values from JSON object `j` and overwrites existing keys. 122. Inserts all values from from range `[first, last)` and overwrites existing keys. 13 14The function is motivated by Python's [dict.update](https://docs.python.org/3.6/library/stdtypes.html#dict.update) 15function. 16 17## Parameters 18 19`j` (in) 20: JSON object to read values from 21 22`first` (in) 23: begin of the range of elements to insert 24 25`last` (in) 26: end of the range of elements to insert 27 28## Exceptions 29 301. The function can throw the following exceptions: 31 - Throws [`type_error.312`](../../home/exceptions.md#jsonexceptiontype_error312) if called on JSON values other than 32 objects; example: `"cannot use update() with string"` 332. The function can throw thw following exceptions: 34 - Throws [`type_error.312`](../../home/exceptions.md#jsonexceptiontype_error312) if called on JSON values other than 35 objects; example: `"cannot use update() with string"` 36 - Throws [`invalid_iterator.202`](../../home/exceptions.md#jsonexceptioninvalid_iterator202) if called on an 37 iterator which does not belong to the current JSON value; example: `"iterator does not fit current value"` 38 - Throws [`invalid_iterator.210`](../../home/exceptions.md#jsonexceptioninvalid_iterator210) if `first` and `last` 39 do not belong to the same JSON value; example: `"iterators do not fit"` 40 41## Complexity 42 431. O(N*log(size() + N)), where N is the number of elements to insert. 442. O(N*log(size() + N)), where N is the number of elements to insert. 45 46## Example 47 48??? example 49 50 The example shows how `update()` is used. 51 52 ```cpp 53 --8<-- "examples/update.cpp" 54 ``` 55 56 Output: 57 58 ```json 59 --8<-- "examples/update.output" 60 ``` 61 62??? example 63 64 The example shows how `update()` is used. 65 66 ```cpp 67 --8<-- "examples/update__range.cpp" 68 ``` 69 70 Output: 71 72 ```json 73 --8<-- "examples/update__range.output" 74 ``` 75 76## Version history 77 78- Added in version 3.0.0. 79