import json
import re


def _get_value(value, type_arg):
    """Returns the value cast into the appropriate Python data type.
    Arguments:
        value: The value to return, in some castable form.
        type_arg (str): One of the following strings: '-bool', '-int', 'string'

    Raises:
        ValueError: If the value is not castable into the specified data type.
        TypeError: If the `type_arg` is not a valid type
    """

    if type_arg == '-bool':
        if value.lower() == 'true':
            return True
        elif value.lower() == 'false':
            return False
        else:
            raise ValueError("'%s' is not a valid boolean." % str(value))
    elif type_arg == '-int':
        try:
            return int(value)
        except ValueError:
            raise ValueError("'%s' is not a valid integer." % str(value))
    elif type_arg == '-string':
        try:
            return str(value)
        except ValueError:
            raise ValueError("Provided value is not a valid string.")
    elif type_arg == '-json':
        try:
            return json.loads(value)
        except ValueError:
            raise ValueError("'%s' is not a valid JSON string representation." %
                             str(value))
    else:
        raise TypeError("The type '%s' is not a supported data type." %
                        re.sub('-', '', str(type_arg)))