def as_bytes(data):
    """Convert input string or json value into bytes.
    """
    if isinstance(data, str):
        return data.encode('utf8')
    if isinstance(data, int):
        return b'%d' % data
    if isinstance(data, float):
        return b'%r' % data
    if isinstance(data, bool):
        return data and b't' or b'f'
    raise ValueError('Invalid input type for hashing: %s' % type(data))
