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

Bug: Benedict to_json converts np.int64 to str #15

Closed
divyanshu16 opened this issue Apr 6, 2020 · 3 comments
Closed

Bug: Benedict to_json converts np.int64 to str #15

divyanshu16 opened this issue Apr 6, 2020 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@divyanshu16
Copy link

Whenever np.int64 datatype comes, benedict is returning str due to which when I json load, I am not seeing number.

json.loads(benedict({"x": [np.int64(0), np.int64(34)]}).to_json())

@fabiocaccamo fabiocaccamo self-assigned this Apr 7, 2020
@fabiocaccamo
Copy link
Owner

fabiocaccamo commented Apr 7, 2020

@divyanshu16 as you can see in the json serializer, all unexpected types are casted to str to avoid encoding errors.

Does it work correctly if you encode it with the standard json encoder?

json.loads(json.dumps({"x": [np.int64(0), np.int64(34)]})))

Keep in mind that with benedict all encoders/decoders can receive their own options using kwargs, it means that you can write your own json encoder and pass it using the default option to to_json method.

@fabiocaccamo fabiocaccamo added enhancement New feature or request question Further information is requested and removed enhancement New feature or request labels Apr 7, 2020
@fabiocaccamo
Copy link
Owner

any feedback?

@divyanshu16
Copy link
Author

Encoder from https://stackoverflow.com/a/47626762/3234468 helps in json load and then applying deep merge using benedict worked for me.

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

No branches or pull requests

2 participants