In json_util with Python 3 we encode bytes to "$binary" but we do not decode "$binary" back into bytes:
>>> from bson.json_util import loads, dumps >>> dumps(b'') '{"$binary": "", "$type": "00"}' >>> loads('{"$binary": "", "$type": "00"}') Binary(b'', 0)
The correct behavior in Python 3 should be:
>>> loads('{"$binary": "", "$type": "00"}')
b''
This would match how the bson module handles bytes. This is a minor backward breaking change for Python 3 users. Code that relies on "$binary" always being decoded into a bson.Binary will break. Code that relies on "$binary" being decoded into bytes should be unaffected as bson.Binary is already a subclass of bytes, eg this code works on Python 2 and 3 before and after this change:
>>> binary = loads('{"$binary": "", "$type": "00"}') >>> assert isinstance(binary, bytes)