def utf8(obj):
    """
    This helper function attempts to decode a string like object to utf-8 encoding.
    For Python2 it just works.
    For Python3 a string object does not have decode mehtod whilst a byte object does.
    """
    try:
        value = obj.decode('utf-8')
    except AttributeError:
        value = obj

    return value