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

Error loading large integer numbers #517

Closed
mighabana opened this issue Sep 20, 2024 · 0 comments
Closed

Error loading large integer numbers #517

mighabana opened this issue Sep 20, 2024 · 0 comments
Labels

Comments

@mighabana
Copy link

mighabana commented Sep 20, 2024

Hi, I just came across this error when loading large integers where the integer extracted using orjson does not match the original large integer. Interestingly, the issue does not occur when loading the json file using json.

Here's the sample json file that I'm reading at "file.json":

{
    "locations": [
        {
            "latitudeE7": 351324213,
            "longitudeE7": -1122434441,
            "accuracy": 10,
            "deviceTag": -80241446968629135069,
            "deviceDesignation": "PRIMARY",
            "timestamp": "2017-12-10T23:14:58.030Z"
        }
    ]
}

This is the python code that I ran to compare the output between orjson and json. To highlight the issue, it occurs in the last 4 digits of the device tag that does not match the values in the original json file.

from pathlib import Path
import json
import orjson

fp = Path('.') / "file.json"

ojson_data = orjson.loads(fp.read_text())

ojson_deviceTag = ojson_data.get('locations')[0].get('deviceTag')
print(ojson_deviceTag ) # -8.024144696862913e+19

json_data = json.loads(fp.read_text())
json_deviceTag = json_data.get('locations')[0].get('deviceTag')
print(json_deviceTag) # -80241446968629135069

# The issue is more obvious when casting to int
print(int(ojson_deviceTag)) # -80241446968629133312
@github-actions github-actions bot added the Stale label Sep 28, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant