コード例 #1
0
    def _from_json(cls, json_string: str) -> "JsonObj":
        """Return a JsonObj object from a json string

        Args:
            json_string (str): JSON string to convert to a JsonObj

        Returns:
            JsonObj: JsonObj object for the given JSON string

        """
        return cls.from_dict(json.loads(json_string))
コード例 #2
0
def jsonify(value: Any) -> Any:
    """Convert and return a value to a JsonObj if the value is a dict"""
    if isinstance(value, dict) and not isinstance(value, JsonObj):
        return JsonObj(value)
    if isinstance(value, list):
        return [jsonify(el) for el in value]
    if isinstance(value, tuple):
        return tuple([jsonify(el) for el in value])
    if isinstance(value, str):
        try:
            data = json.loads(value)
            return jsonify(data)
        except Exception:
            pass

    return value
コード例 #3
0
 def parse(string: str, obj: bool = True) -> Any:
     """Parse JSON string/bytes and jsonify all dictionaries -> JsonObj"""
     if obj:
         return jsonify(json.loads(string))
     return json.loads(string)
コード例 #4
0
 def loads(string: str, obj: bool = False, **kwargs: Any) -> Any:
     """Parse JSON string/bytes and return raw representation"""
     if obj:
         return jsonify(json.loads(string, **kwargs))
     return json.loads(string, **kwargs)
コード例 #5
0
def test_uno():
    from jsonbourne import json

    dictionary = {"a": 1, "b": 2, "c": 3}
    string = json.dumps(dictionary)
    assert dictionary == json.loads(string)
コード例 #6
0
 def from_json(cls, json_string: str):
     return cls(**json.loads(json_string))
コード例 #7
0
 def from_json(cls, json_string: str):
     return JsonSubObj(json.loads(json_string))