wasp/waspy · parser.py
python logo
def decode(self, data: bytes):
        if data:
            try:
                return json.loads(data)
            except json.JSONDecodeError:
                raise ParseError("Invalid JSON")
Similar code snippets
1.
NicolasLM/atoma · json_feed.py
Match rating: 67.6% · See similar code snippets
python logo
def parse_json_feed_bytes(data: bytes) -> JSONFeed:
    """Parse a JSON feed from a byte-string containing JSON data."""
    try:
        root = json.loads(data)
    except json.decoder.JSONDecodeError:
        raise FeedJSONError('Not a valid JSON document')

    return parse_json_feed(root)
2.
ethereum/web3.py · encoding.py
Match rating: 65.65% · See similar code snippets
python logo
def json_decode(self, json_str):
        try:
            decoded = json.loads(json_str)
            return decoded
        except json.decoder.JSONDecodeError as exc:
            err_msg = 'Could not decode {} because of {}.'.format(repr(json_str), exc)
            # Calling code may rely on catching JSONDecodeError to recognize bad json
            # so we have to re-raise the same type.
            raise json.decoder.JSONDecodeError(err_msg, exc.doc, exc.pos)
3.
duniter/duniter-python-api · client.py
Match rating: 65.34% · See similar code snippets
python logo
def parse_error(text: str) -> Any:
    """
    Validate and parse the BMA answer from websocket

    :param text: the bma error
    :return: the json data
    """
    try:
        data = json.loads(text)
        jsonschema.validate(data, ERROR_SCHEMA)
    except (TypeError, json.decoder.JSONDecodeError) as e:
        raise jsonschema.ValidationError("Could not parse json : {0}".format(str(e)))

    return data
4.
praekeltfoundation/seed-control-interface-service · utils.py
Match rating: 64.63% · See similar code snippets
python logo
def json_decode(data):
    """
    Decodes the given JSON as primitives
    """
    if isinstance(data, six.binary_type):
        data = data.decode('utf-8')

    return json.loads(data)
5.
MisterY/gnucash-portfolio · generic.py
Match rating: 64.49% · See similar code snippets
python logo
def validate_json(data: str):
    """ Validate JSON by parsing string data. Returns the json dict. """
    result = None
    try:
        result = json.loads(data)
    except ValueError as error:
        log(ERROR, "invalid json: %s", error)

    return result
6.
duniter/duniter-python-api · client.py
Match rating: 63.32% · See similar code snippets
python logo
def parse_text(text: str, schema: dict) -> Any:
    """
    Validate and parse the BMA answer from websocket

    :param text: the bma answer
    :param schema: dict for jsonschema
    :return: the json data
    """
    try:
        data = json.loads(text)
        jsonschema.validate(data, schema)
    except (TypeError, json.decoder.JSONDecodeError):
        raise jsonschema.ValidationError("Could not parse json")

    return data
7.
RIPE-NCC/ripe.atlas.sagan · base.py
Match rating: 63.17% · See similar code snippets
python logo
def loads(*args, **kwargs):
        try:
            if json.__name__ == "ujson":
                return json.loads(*args, **kwargs)
            return json.loads(strict=False, *args, **kwargs)
        except ValueError:
            raise ResultParseError("The JSON result could not be parsed")
8.
openshift/openshift-restclient-python · client.py
Match rating: 62.96% · See similar code snippets
python logo
def load_json(response):
    if six.PY2:
        return json.loads(response.data)
    return json.loads(response.data.decode('utf8'))
9.
ifduyue/urlfetch · urlfetch.py
Match rating: 62.95% · See similar code snippets
python logo
def json(self):
        """Load response body as json.

        :raises: :class:`ContentDecodingError`
        """
        try:
            return json.loads(self.text)
        except Exception as e:
            raise ContentDecodingError(e)
10.
RudolfCardinal/pythonlib · serialize.py
Match rating: 62.15% · See similar code snippets
python logo
def json_decode(s: str) -> Any:
    """
    Decodes an object from JSON using our custom decoder.
    """
    try:
        return json.JSONDecoder(object_hook=json_class_decoder_hook).decode(s)
    except json.JSONDecodeError:
        log.warning("Failed to decode JSON (returning None): {!r}", s)
        return None