(data: Any, pretty: bool = False)
| 13 | |
| 14 | |
| 15 | def dump_json(data: Any, pretty: bool = False) -> str: |
| 16 | if ORJSON: |
| 17 | orjson_params: dict[str, Any] = {"default": str} |
| 18 | if pretty: |
| 19 | orjson_params["option"] = ( |
| 20 | orjson.OPT_INDENT_2 | orjson.OPT_APPEND_NEWLINE # type: ignore |
| 21 | ) |
| 22 | return orjson.dumps(data, **orjson_params).decode( # type: ignore |
| 23 | "utf8" |
| 24 | ) |
| 25 | else: |
| 26 | params: dict[str, Any] = {"default": str} |
| 27 | if pretty: |
| 28 | params["indent"] = 2 |
| 29 | return json.dumps(data, **params) # type: ignore |
| 30 | |
| 31 | |
| 32 | class JSONDict(dict): |
no outgoing calls