Skip to content

Latest commit

 

History

History
59 lines (42 loc) · 1.01 KB

merge_or_update.md

File metadata and controls

59 lines (42 loc) · 1.01 KB

jsoncons::basic_json::merge_or_update

void merge_or_update(const basic_json& source); // (1)
void merge_or_update(basic_json&& source); // (2)
void merge_or_update(object_iterator hint, const basic_json& source); // (3)
void merge_or_update(object_iterator hint, basic_json&& source); // (4)

Inserts another json object's key-value pairs into a json object, or assigns them if they already exist.

The merge_or_update function performs only a one-level-deep shallow merge, not a deep merge of nested objects.

Parameters

source `json` object value

Return value

None

Exceptions

Throws std::domain_error if source or *this are not json objects.

Examples

Merge or update json

json j = json::parse(R"(
{
    "a" : 1,
    "b" : 2
}
)");

const json source = json::parse(R"(
{
    "a" : 2,
    "c" : 3
}
)");

j1.merge_or_update(source);

std::cout << j << endl;

Output:

{"a":2,"b":2,"c":3}