• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# basic_json::diff
2
3```cpp
4static basic_json diff(const basic_json& source,
5                       const basic_json& target);
6```
7
8Creates a [JSON Patch](http://jsonpatch.com) so that value `source` can be changed into the value `target` by calling
9[`patch`](patch.md) function.
10
11For two JSON values `source` and `target`, the following code yields always `#!cpp true`:
12```cpp
13source.patch(diff(source, target)) == target;
14```
15
16## Parameters
17
18`source` (in)
19:   JSON value to compare from
20
21`target` (in)
22:   JSON value to compare against
23
24## Return value
25
26a JSON patch to convert the `source` to `target`
27
28## Exception safety
29
30Strong guarantee: if an exception is thrown, there are no changes in the JSON value.
31
32## Complexity
33
34Linear in the lengths of `source` and `target`.
35
36## Note
37
38Currently, only `remove`, `add`, and `replace` operations are generated.
39
40## Example
41
42??? example
43
44    The following code shows how a JSON patch is created as a diff for two JSON values.
45
46    ```cpp
47    --8<-- "examples/diff.cpp"
48    ```
49
50    Output:
51
52    ```json
53    --8<-- "examples/diff.output"
54    ```
55
56## Version history
57
58- Added in version 2.0.0.
59