JSON for Modern C++ 3.8.0

accept
accept
accept
allocator_type
array
array_t
at
at
at
at
at
at
back
back
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
basic_json
begin
begin
binary
binary
binary
binary
binary_t
boolean_t
cbegin
cbor_tag_handler_t
cend
clear
const_iterator
const_pointer
const_reference
const_reverse_iterator
contains
contains
count
crbegin
crend
detail::external_constructor
diff
difference_type
dump
emplace
emplace_back
empty
end
end
erase
erase
erase
erase
error_handler_t
exception
find
find
flatten
from_bson
from_bson
from_bson
from_bson
from_cbor
from_cbor
from_cbor
from_cbor
from_msgpack
from_msgpack
from_msgpack
from_msgpack
from_ubjson
from_ubjson
from_ubjson
from_ubjson
front
front
get
get
get
get
get
get
get_allocator
get_binary
get_binary
get_ptr
get_ptr
get_ref
get_ref
get_to
get_to
get_to
initializer_list_t
input_format_t
insert
insert
insert
insert
insert
insert
insert_iterator
invalid_iterator
is_array
is_binary
is_boolean
is_discarded
is_null
is_number
is_number_float
is_number_integer
is_number_unsigned
is_object
is_primitive
is_string
is_structured
items
items
iterator
iterator_wrapper
iterator_wrapper
json_pointer
json_sax_t
json_serializer
max_size
merge_patch
meta
number_float_t
number_integer_t
number_unsigned_t
object
object_comparator_t
object_t
operator value_t
operator ValueType
operator!=
operator!=
operator!=
operator+=
operator+=
operator+=
operator+=
operator<
operator<
operator<
operator<<
operator<<
operator<=
operator<=
operator<=
operator=
operator==
operator==
operator==
operator>
operator>
operator>
operator>=
operator>=
operator>=
operator>>
operator>>
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
operator[]
other_error
out_of_range
parse
parse
parse
parse_error
parse_event_t
parser_callback_t
patch
pointer
push_back
push_back
push_back
push_back
rbegin
rbegin
reference
rend
rend
reverse_iterator
sax_parse
sax_parse
sax_parse
size
size_type
string_t
swap
swap
swap
swap
swap
swap
swap
to_bson
to_bson
to_bson
to_cbor
to_cbor
to_cbor
to_msgpack
to_msgpack
to_msgpack
to_ubjson
to_ubjson
to_ubjson
type
type_error
type_name
unflatten
update
update
value
value
value
value
value_t
value_type
~basic_json
| ## ◆ merge_patch()
void nlohmann::basic_json::merge_patch | ( | const basic_json & | apply_patch | ) |
| inline
  The merge patch format is primarily intended for use with the HTTP PATCH method as a means of describing a set of modifications to a target resource's content. This function applies a merge patch to the current JSON value. The function implements the following algorithm from Section 2 of RFC 7396 (JSON Merge Patch): define MergePatch(Target, Patch): if Patch is an Object: if Target is not an Object: Target = {} // Ignore the contents and set it to an empty Object for each Name/Value pair in Patch: if Value is null: if Name exists in Target: remove the Name/Value pair from Target else: Target[Name] = MergePatch(Target[Name], Value) return Target else: return Patch Thereby, `Target` is the current object; that is, the patch is applied to the current value. Parameters
  [in] | apply_patch | the patch to apply
  Complexity Linear in the lengths of patch. Example The following code shows how a JSON Merge Patch is applied to a JSON document. 1 #include <iostream> 2 #include <nlohmann/json.hpp> 3 #include <iomanip> // for std::setw 4 5 using json = nlohmann::json; 6 7 int main() 8 { 9 // the original document 10 json document = R"({ 11 "title": "Goodbye!", 12 "author": { 13 "givenName": "John", 14 "familyName": "Doe" 15 }, 16 "tags": [ 17 "example", 18 "sample" 19 ], 20 "content": "This will be unchanged" 21 })"_json; 22 23 // the patch 24 json patch = R"({ 25 "title": "Hello!", 26 "phoneNumber": "+01-123-456-7890", 27 "author": { 28 "familyName": null 29 }, 30 "tags": [ 31 "example" 32 ] 33 })"_json; 34 35 // apply the patch 36 document.merge_patch(patch); 37 38 // output original and patched document 39 std::cout << std::setw(4) << document << std::endl; 40 } Output (play with this example online):
      {
          "author": {
              "givenName": "John"
          },
          "content": "This will be unchanged",
          "phoneNumber": "+01-123-456-7890",
          "tags": [
              "example"
          ],
          "title": "Hello!"
      }
  The example code above can be translated with
      g++ -std=c++11 -Isingle_include doc/examples/merge_patch.cpp -o merge_patch
See also patch – apply a JSON patch RFC 7396 (JSON Merge Patch) Since version 3.0.0 Definition at line 25043 of file json.hpp.

nlohmann::basic_json::merge_patch
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition: json.hpp:25043
nlohmann::json
basic_json<> json
default JSON class
Definition: json.hpp:2933
nlohmann::basic_json::patch
basic_json patch(const basic_json &json_patch) const
applies a JSON patch
Definition: json.hpp:24572