Skip to content

Commit 2d2102c

Browse files
committed
add docs for commandline utilities
1 parent 217ef38 commit 2d2102c

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

doc/commandline.rst

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

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and PyPy are supported.
1818

1919
tutorial
2020
mod-jsonpatch
21+
commandline
2122
RFC 6902 <http://tools.ietf.org/html/rfc6902>
2223

2324

0 commit comments

Comments
 (0)