ansible-jsonpatch icon indicating copy to clipboard operation
ansible-jsonpatch copied to clipboard

UTF-8 not supported?

Open angrybb opened this issue 3 years ago • 1 comments

I have UTF-8 encoded JSON file with string: März_Lebensmittel but module changes file encoding to ASCII and string becomes: M\u00e4rz_Lebensmittel

Is UTF-8 supported?

angrybb avatar Aug 31 '21 15:08 angrybb

This is dictated by the ensure_ascii argument to json.dump().

If ensure_ascii is true (the default), the output is guaranteed to have all incoming non-ASCII characters escaped. If ensure_ascii is false, these characters will be output as-is.

It looks like json_patch.py does not explicitly pass ensure_ascii (or offer the ability to override this currently), so that parameter implicitly defaults to True and escapes non-ASCII characters as you are seeing here.

To "support" this:

  • You could simply pass ensure_ascii=False in your own fork of json_patch.py to the various json.dump[s] calls in the module
  • Or the module itself could be modified to add an Ansible argument (here)

brsolomon-deloitte avatar Dec 21 '21 14:12 brsolomon-deloitte