(obj: object, debug: bool = False)
| 943 | |
| 944 | |
| 945 | def json_dumps(obj: object, debug: bool = False) -> bytes: |
| 946 | if orjson is not None: |
| 947 | if debug: |
| 948 | dumps_option = orjson.OPT_INDENT_2 | orjson.OPT_SORT_KEYS |
| 949 | else: |
| 950 | # TODO: If we don't sort keys here, testIncrementalInternalScramble fails |
| 951 | # We should document exactly what is going on there |
| 952 | dumps_option = orjson.OPT_SORT_KEYS |
| 953 | |
| 954 | try: |
| 955 | return orjson.dumps(obj, option=dumps_option) # type: ignore[no-any-return] |
| 956 | except TypeError as e: |
| 957 | if str(e) != "Integer exceeds 64-bit range": |
| 958 | raise |
| 959 | |
| 960 | if debug: |
| 961 | return json.dumps(obj, indent=2, sort_keys=True).encode("utf-8") |
| 962 | else: |
| 963 | # See above for sort_keys comment |
| 964 | return json.dumps(obj, sort_keys=True, separators=(",", ":")).encode("utf-8") |
| 965 | |
| 966 | |
| 967 | def json_loads(data: bytes) -> Any: |
no test coverage detected
searching dependent graphs…