-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathjsondiff.py
More file actions
executable file
·40 lines (30 loc) · 1009 Bytes
/
jsondiff.py
File metadata and controls
executable file
·40 lines (30 loc) · 1009 Bytes
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
import json
import argparse
from .. import __version__, make_patch
parser = argparse.ArgumentParser(description='Diff two JSON files')
parser.add_argument('FILE1', type=argparse.FileType('r'))
parser.add_argument('FILE2', type=argparse.FileType('r'))
parser.add_argument('--indent', type=int, default=None,
help='Indent output by n spaces')
parser.add_argument('-v', '--version', action='version',
version='%(prog)s ' + __version__)
def main():
try:
diff_files()
except KeyboardInterrupt:
sys.exit(1)
def diff_files():
""" Diffs two JSON files and prints a patch """
args = parser.parse_args()
doc1 = json.load(args.FILE1)
doc2 = json.load(args.FILE2)
patch = make_patch(doc1, doc2)
if patch.patch:
print(json.dumps(patch.patch, indent=args.indent))
sys.exit(1)
if __name__ == "__main__":
main()