diff options
author | Genzer Hawker <genzers@gmail.com> | 2021-03-03 14:24:31 +0700 |
---|---|---|
committer | Genzer Hawker <genzers@gmail.com> | 2021-03-03 14:54:40 +0700 |
commit | 974d54f393de78ce21bee9897cee8f1ace5813ee (patch) | |
tree | e0eee3753a354820e913d6e2e7958a0d16f0d3e2 /doc | |
parent | dbea3db33298da4ec41197b07612c42580e132e4 (diff) | |
download | python-json-patch-974d54f393de78ce21bee9897cee8f1ace5813ee.tar.gz |
Add support for preserving Unicode characters in jsonpatch CLI
If the JSON content contains some Unicode characters, the jsonpatch
final output will encode the Unicode character using ASCII (i.e
`\u0394`). This behaviour comes from the module `json.dump()` governed
by a flag `ensure_ascii`[1].
For example:
```json
/* patch.json */
[{
"op": "add",
"path": "/SomeUnicodeSamples",
"value": "𝒞𝘋𝙴𝓕ĢȞỈ𝕵 đ áê 🤩 äÄöÖüÜß"
}]
```
After applying the patch on an empty source file `{}`, this is the
output:
```json
{"SomeUnicodeSamples": "\ud835\udc9e\ud835\ude0b...\u00fc\u00dc\u00df"}
```
This commit adds a flag `-u|--preserve-unicode` in the jsonpatch CLI
to configure the behaviour of `json.dump`'s `ensure_ascii` flag.
Using the `--preserve-unicode` flag, the cli will print the Unicode
characters as-is without any encoding.
[1]: https://docs.python.org/3/library/json.html#basic-usage
Diffstat (limited to 'doc')
-rw-r--r-- | doc/commandline.rst | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/doc/commandline.rst b/doc/commandline.rst index 5644d08..5fb9a3c 100644 --- a/doc/commandline.rst +++ b/doc/commandline.rst @@ -74,10 +74,12 @@ The program ``jsonpatch`` is used to apply JSON patches on JSON files. :: 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 - + -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 ^^^^^^^ |