<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_type(value, ptype):
 """ Convert value to ptype """

    if ptype == 'str':
        return str(value)
    elif ptype == 'int':
        return int(value)
    elif ptype == 'float':
        return float(value)
    elif ptype == 'bool':
        if value.lower() == 'true':
            return True
        elif value.lower() == 'false':
            return False
        raise ValueError('Bad bool value: %s' % value)
    elif ptype == 'json':
        return json.loads(value)

    return ValueError('Unknown type')