TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ merge_patch()

template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
void nlohmann::basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType >::merge_patch ( const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > &  apply_patch)
inline

applies a JSON Merge Patch

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_patchthe patch to apply

@complexity Linear in the lengths of patch.

@liveexample{The following code shows how a JSON Merge Patch is applied to a JSON document.,merge_patch}

See also
see patch – apply a JSON patch
RFC 7396 (JSON Merge Patch)
Since
version 3.0.0

Definition at line 26651 of file json.hpp.

26652 {
26653 if (apply_patch.is_object())
26654 {
26655 if (!is_object())
26656 {
26657 *this = object();
26658 }
26659
26660 for (auto it = apply_patch.begin(); it != apply_patch.end(); ++it)
26661 {
26662 if (it.value().is_null())
26663 {
26664 erase(it.key());
26665 }
26666
26667 else
26668 {
26669 operator[](it.key()).merge_patch(it.value());
26670 }
26671 }
26672 }
26673
26674 else
26675 {
26676 *this = apply_patch;
26677 }
26678 }
IteratorType erase(IteratorType pos)
remove element given an iterator
Definition: json.hpp:21920
constexpr bool is_object() const noexcept
return whether value is an object
Definition: json.hpp:20410
void merge_patch(const basic_json &apply_patch)
applies a JSON Merge Patch
Definition: json.hpp:26651
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json object(initializer_list_t init={})
explicitly create an object from an initializer list
Definition: json.hpp:19662
reference operator[](size_type idx)
access specified array element
Definition: json.hpp:21385