stefankoegl / python-json-patch

Applying JSON Patches in Python
https://python-json-patch.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
434 stars 94 forks source link

Add support for preserving Unicode characters in jsonpatch CLI #127

Closed Genzer closed 3 years ago

Genzer commented 3 years ago

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_ascii1.

For example:

/* patch.json */
[{
  "op": "add",
  "path": "/SomeUnicodeSamples",
  "value": "𝒞𝘋𝙴𝓕ĢȞỈ𝕵 đ áê 🤩 äÄöÖüÜß"
}]

After applying the patch on an empty source file {}, this is the output:

{"SomeUnicodeSamples": "\ud835\udc9e\ud835\ude0b...\u00fc\u00dc\u00df"}

This commits add a flag -u|--preserve-unicode into the jsonpatch CLI to configure the behaviour of json.dump's ensure_ascii flag.

Using the --preserve-unicode flag, the final output will print the Unicode characters as-is without any encoding.

coveralls commented 3 years ago

Coverage Status

Coverage remained the same at 65.846% when pulling 974d54f393de78ce21bee9897cee8f1ace5813ee on Genzer:master into dbea3db33298da4ec41197b07612c42580e132e4 on stefankoegl:master.

stefankoegl commented 3 years ago

Looks good, thanks :)