Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
541b4613
Unverified
Commit
541b4613
authored
Jan 14, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
♻
adjusted code to split headers
parent
0e8f01a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
78 additions
and
1 deletion
+78
-1
develop/json.hpp
develop/json.hpp
+78
-0
src/json.hpp
src/json.hpp
+0
-1
No files found.
develop/json.hpp
View file @
541b4613
...
@@ -7397,6 +7397,7 @@ class basic_json
...
@@ -7397,6 +7397,7 @@ class basic_json
diff for two JSON values.,diff}
diff for two JSON values.,diff}
@sa @ref patch -- apply a JSON patch
@sa @ref patch -- apply a JSON patch
@sa @ref merge_patch -- apply a JSON Merge Patch
@sa [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
@sa [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902)
...
@@ -7528,6 +7529,83 @@ class basic_json
...
@@ -7528,6 +7529,83 @@ class basic_json
}
}
/// @}
/// @}
////////////////////////////////
// JSON Merge Patch functions //
////////////////////////////////
/// @name JSON Merge Patch functions
/// @{
/*!
@brief 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)](https://tools.ietf.org/html/rfc7396):
```
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.
@param[in] patch the patch to apply
@complexity Linear in the lengths of @a patch.
@liveexample{The following code shows how a JSON Merge Patch is applied to
a JSON document.,merge_patch}
@sa @ref patch -- apply a JSON patch
@sa [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396)
@since version 3.0.0
*/
void
merge_patch
(
const
basic_json
&
patch
)
{
if
(
patch
.
is_object
())
{
if
(
not
is_object
())
{
*
this
=
object
();
}
for
(
auto
it
=
patch
.
begin
();
it
!=
patch
.
end
();
++
it
)
{
if
(
it
.
value
().
is_null
())
{
erase
(
it
.
key
());
}
else
{
operator
[](
it
.
key
()).
merge_patch
(
it
.
value
());
}
}
}
else
{
*
this
=
patch
;
}
}
/// @}
};
};
//////////////////
//////////////////
...
...
src/json.hpp
View file @
541b4613
...
@@ -14894,7 +14894,6 @@ class basic_json
...
@@ -14894,7 +14894,6 @@ class basic_json
}
}
/// @}
/// @}
};
};
//////////////////
//////////////////
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment