1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
Commandline Utilities
=====================
The JSON patch package contains the commandline utilities ``jsondiff`` and
``jsonpatch``.
``jsondiff``
------------
The program ``jsondiff`` can be used to create a JSON patch by comparing two
JSON files ::
usage: jsondiff [-h] [--indent INDENT] [-v] FILE1 FILE2
Diff two JSON files
positional arguments:
FILE1
FILE2
optional arguments:
-h, --help show this help message and exit
--indent INDENT Indent output by n spaces
-v, --version show program's version number and exit
Example
^^^^^^^
.. code-block:: bash
# inspect JSON files
$ cat a.json
{ "a": [1, 2], "b": 0 }
$ cat b.json
{ "a": [1, 2, 3], "c": 100 }
# show patch in "dense" representation
$ jsondiff a.json b.json
[{"path": "/a/2", "value": 3, "op": "add"}, {"path": "/b", "op": "remove"}, {"path": "/c", "value": 100, "op": "add"}]
# show patch with some indentation
$ jsondiff a.json b.json --indent=2
[
{
"path": "/a/2",
"value": 3,
"op": "add"
},
{
"path": "/b",
"op": "remove"
},
{
"path": "/c",
"value": 100,
"op": "add"
}
]
``jsonpatch``
-------------
The program ``jsonpatch`` is used to apply JSON patches on JSON files. ::
usage: jsonpatch [-h] [--indent INDENT] [-v] ORIGINAL PATCH
Apply a JSON patch on a JSON files
positional arguments:
ORIGINAL Original file
PATCH Patch file
optional arguments:
-h, --help show this help message and exit
--indent INDENT Indent output by n spaces
-b, --backup Back up ORIGINAL if modifying in-place
-i, --in-place Modify ORIGINAL in-place instead of to stdout
-v, --version show program's version number and exit
-u, --preserve-unicode Output Unicode character as-is without using Code Point
Example
^^^^^^^
.. code-block:: bash
# create a patch
$ jsondiff a.json b.json > patch.json
# show the result after applying a patch
$ jsonpatch a.json patch.json
{"a": [1, 2, 3], "c": 100}
$ jsonpatch a.json patch.json --indent=2
{
"a": [
1,
2,
3
],
"c": 100
}
# pipe result into new file
$ jsonpatch a.json patch.json --indent=2 > c.json
# c.json now equals b.json
$ jsondiff b.json c.json
[]
|