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))
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
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)
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)
def test_uno(): from jsonbourne import json dictionary = {"a": 1, "b": 2, "c": 3} string = json.dumps(dictionary) assert dictionary == json.loads(string)
def from_json(cls, json_string: str): return cls(**json.loads(json_string))
def from_json(cls, json_string: str): return JsonSubObj(json.loads(json_string))