Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Integer exceeds 64-bit range #301

Closed
mailgyc opened this issue Sep 8, 2022 · 2 comments
Closed

TypeError: Integer exceeds 64-bit range #301

mailgyc opened this issue Sep 8, 2022 · 2 comments

Comments

@mailgyc
Copy link

mailgyc commented Sep 8, 2022

We replace json with orjson, it works well, until today we meet some really large number, see the code below.
Does there have a plan support integer large than 64bit ?

import json
json.dumps(18528528433540659662)

'18528528433540659662'

import orjson
orjson.dumps(18528528433540659662)

TypeError: Integer exceeds 64-bit range

@waketzheng
Copy link

Read this issue #116

Or, use a custom function:

import json
from typing import Any

import orjson


def json_dumps(obj: Any) -> str:
    try:
        return orjson.dumps(obj).decode()
    except TypeError as e:
        if str(e) == 'Integer exceeds 64-bit range':
            return json.dumps(obj)
        raise e

@ijl ijl closed this as completed Sep 9, 2022
@mailgyc
Copy link
Author

mailgyc commented Sep 12, 2022

Thanks, the costom function helps a lot👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants