make json encoding more robust in the face of binary data