-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ implemented JSON Merge Patch (RFC 7396)
SQLite's json1 extension (https://www.sqlite.org/json1.html) supports JSON Merge Patch (https://tools.ietf.org/html/rfc7396). As the implementation is trivial and we already support JSON Patch, I think this could be a nice extension to the library.
- Loading branch information
Showing
6 changed files
with
393 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <iostream> | ||
#include "json.hpp" | ||
#include <iomanip> // for std::setw | ||
|
||
using json = nlohmann::json; | ||
|
||
int main() | ||
{ | ||
// the original document | ||
json document = R"({ | ||
"title": "Goodbye!", | ||
"author": { | ||
"givenName": "John", | ||
"familyName": "Doe" | ||
}, | ||
"tags": [ | ||
"example", | ||
"sample" | ||
], | ||
"content": "This will be unchanged" | ||
})"_json; | ||
|
||
// the patch | ||
json patch = R"({ | ||
"title": "Hello!", | ||
"phoneNumber": "+01-123-456-7890", | ||
"author": { | ||
"familyName": null | ||
}, | ||
"tags": [ | ||
"example" | ||
] | ||
})"_json; | ||
|
||
// apply the patch | ||
document.merge_patch(patch); | ||
|
||
// output original and patched document | ||
std::cout << std::setw(4) << document << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<a target="_blank" href="https://wandbox.org/permlink/h13IsbffwmMfqsej"><b>online</b></a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"author": { | ||
"givenName": "John" | ||
}, | ||
"content": "This will be unchanged", | ||
"phoneNumber": "+01-123-456-7890", | ||
"tags": [ | ||
"example" | ||
], | ||
"title": "Hello!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.