diff options
author | Stefan Kögl <stefan@skoegl.net> | 2013-10-12 12:20:38 +0200 |
---|---|---|
committer | Stefan Kögl <stefan@skoegl.net> | 2013-10-12 12:20:38 +0200 |
commit | 2d2102c5e9aa8f2c915fa66d4eeb1db64a7bc221 (patch) | |
tree | be8ef0ddc0d7071125c397e7cf3bd926f4224968 | |
parent | 217ef382701af1c62a12121957dd191d355ce60f (diff) | |
download | python-json-patch-2d2102c5e9aa8f2c915fa66d4eeb1db64a7bc221.tar.gz |
add docs for commandline utilities
-rw-r--r-- | doc/commandline.rst | 110 | ||||
-rw-r--r-- | doc/index.rst | 1 |
2 files changed, 111 insertions, 0 deletions
diff --git a/doc/commandline.rst b/doc/commandline.rst new file mode 100644 index 0000000..5644d08 --- /dev/null +++ b/doc/commandline.rst @@ -0,0 +1,110 @@ +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 + -v, --version show program's version number and exit + + +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 + [] + diff --git a/doc/index.rst b/doc/index.rst index 8ff216d..674c9e5 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -18,6 +18,7 @@ and PyPy are supported. tutorial mod-jsonpatch + commandline RFC 6902 <http://tools.ietf.org/html/rfc6902> |