Commit 6ee6d444 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Check unserialised types in json.py

parent 231bae0e
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -61,7 +61,10 @@ class JSONObject(JSONPathMixin, dict[str, Any]):
		"""
		Create a JSONObject from a JSON string
		"""
		return cls(orjson.loads(string))
		obj = orjson.loads(string)
		if not isinstance(obj, dict):
			raise TypeError(f"expected a JSON mapping, got {type(obj)}")
		return cls(obj)


class JSONArray(JSONPathMixin, list[Any]):
@@ -76,4 +79,7 @@ class JSONArray(JSONPathMixin, list[Any]):
		"""
		Create a JSONArray from a JSON string
		"""
		return cls(orjson.loads(string))
		obj = orjson.loads(string)
		if not isinstance(obj, list):
			raise TypeError(f"expected a JSON array, got {type(obj)}")
		return cls(obj)