Serializing Python bytestrings to JSON, preserving ordinal character values
Is there a way to encode bytestrings to Unicode strings that preserves ordinal character values?
The byte ->
unicode transformation is called decode
, not encode
. But yes, decoding with a codec such as iso-8859-1
should indeed "preserve ordinal character values" as you wish.
Could you just use Base64? (Python base64
module, Javascript has several implementations, one of which is here.)
No reason to use escaped ASCII or UTF-8 unless your data is almost all text.