Add support for JSON fragments (#107213)

This commit is contained in:
J. Nick Koston
2024-01-07 17:36:31 -10:00
committed by GitHub
parent 50edc334de
commit d04e2d56da
11 changed files with 289 additions and 103 deletions

View File

@ -45,6 +45,8 @@ def json_encoder_default(obj: Any) -> Any:
Hand other objects to the original method.
"""
if hasattr(obj, "json_fragment"):
return obj.json_fragment
if isinstance(obj, (set, tuple)):
return list(obj)
if isinstance(obj, float):
@ -114,6 +116,9 @@ def json_bytes_strip_null(data: Any) -> bytes:
return json_bytes(_strip_null(orjson.loads(result)))
json_fragment = orjson.Fragment
def json_dumps(data: Any) -> str:
r"""Dump json string.