예제 #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))