mirror of
https://github.com/nlohmann/json.git
synced 2026-10-27 08:18:55 +00:00
Add See also links in both directions between the concept pages (features, home, integration) and the API pages, write API links in code font, give every entry a comment after a dash, and show the callback event figure on the parser callbacks page. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1.6 KiB
1.6 KiB
nlohmann::basic_json::diff
static basic_json diff(const basic_json& source,
const basic_json& target);
Creates a JSON Patch so that value source can be changed into the value target by calling
patch function.
For two JSON values source and target, the following code always yields #!cpp true:
source.patch(diff(source, target)) == target;
Parameters
source(in)- JSON value to compare from
target(in)- JSON value to compare against
Return value
a JSON patch to convert the source to target
Exception safety
Strong guarantee: source and target are never modified.
Complexity
Linear in the lengths of source and target.
Notes
Currently, only remove, add, and replace operations are generated.
Examples
??? example
The following code shows how a JSON patch is created as a diff for two JSON values.
```cpp
--8<-- "examples/diff.cpp"
```
Output:
```json
--8<-- "examples/diff.output"
```
See also
- RFC 6902 (JSON Patch) - specification of JSON Patch
patch- applies a JSON Patchpatch_inplace- applies a JSON Patch in placemerge_patch- applies a JSON Merge Patchmerge_diff- creates a diff as a JSON Merge Patch- JSON Patch and Diff - the article on JSON Patch
Version history
- Added in version 2.0.0.