Skip to content

Commit a76f742

Browse files
authored
feat(jsondiff): Add support for preserving Unicode characters (stefankoegl#145)
Mostly same as stefankoegl#127
1 parent 714df3c commit a76f742

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

bin/jsondiff

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ parser.add_argument('FILE1', type=argparse.FileType('r'))
1414
parser.add_argument('FILE2', type=argparse.FileType('r'))
1515
parser.add_argument('--indent', type=int, default=None,
1616
help='Indent output by n spaces')
17+
parser.add_argument('-u', '--preserve-unicode', action='store_true',
18+
help='Output Unicode character as-is without using Code Point')
1719
parser.add_argument('-v', '--version', action='version',
1820
version='%(prog)s ' + jsonpatch.__version__)
1921

@@ -32,7 +34,7 @@ def diff_files():
3234
doc2 = json.load(args.FILE2)
3335
patch = jsonpatch.make_patch(doc1, doc2)
3436
if patch.patch:
35-
print(json.dumps(patch.patch, indent=args.indent))
37+
print(json.dumps(patch.patch, indent=args.indent, ensure_ascii=not(args.preserve_unicode)))
3638
sys.exit(1)
3739

3840
if __name__ == "__main__":

doc/commandline.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ The JSON patch package contains the commandline utilities ``jsondiff`` and
1010
The program ``jsondiff`` can be used to create a JSON patch by comparing two
1111
JSON files ::
1212

13-
usage: jsondiff [-h] [--indent INDENT] [-v] FILE1 FILE2
13+
usage: jsondiff [-h] [--indent INDENT] [-u] [-v] FILE1 FILE2
1414

1515
Diff two JSON files
1616

@@ -19,9 +19,10 @@ JSON files ::
1919
FILE2
2020

2121
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
22+
-h, --help show this help message and exit
23+
--indent INDENT Indent output by n spaces
24+
-u, --preserve-unicode Output Unicode character as-is without using Code Point
25+
-v, --version show program's version number and exit
2526

2627
Example
2728
^^^^^^^

0 commit comments

Comments
 (0)