import base64


def bytes_to_json_string(data: bytes) -> str:
    """
    Given binary data, return a string representation
    that can be safely used in a JSON object.
    """
    # NOTE: we can't just return 'data.decode()', because that won't work
    # if 'data' is not in a given encoding (e.g. utf-8), as is the case
    # when e.g. 'data' is gzip-compressed.
    return base64.encodebytes(data).decode("utf-8")