I like to import regular expressions using binary strings like
ReplaceChars = (
('UTF8 HYPHEN ' , b'\xe2\x80\x90', b'\x2d'),
('UTF8 EN DASH' , b'\xe2\x80\x93', b'\x2d'),
('UTF8 EM DASH' , b'\xe2\x80\x94', b'\x2d'),
)
Currently this is hardcoded in my python source, but I like to to have it in a different file to be more flexible.
I normally use json.load(jsonfile) to do this, but it seems that json is not working with the binary strings...
I tried to dump ReplaceChars into a json file:
with open('result.json', 'w') as f:
json.dump(ReplaceChars, f)
but it causes the following error:
Traceback (most recent call last):
[...]
TypeError: Object of type 'bytes' is not JSON serializable
Is there a workaround in json?