Commit 974d54f
committed
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-usage1 parent dbea3db commit 974d54f
2 files changed
+10
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
75 | | - | |
76 | | - | |
| 76 | + | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| |||
0 commit comments