Apparently json.dump produces mixed bytes/unicode content. So now we use json.dumps wrapped in to_bytes and that's it.