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

parse_float support to allow decimal decoding #401

Open
vincentmele opened this issue Apr 6, 2020 · 0 comments
Open

parse_float support to allow decimal decoding #401

vincentmele opened this issue Apr 6, 2020 · 0 comments

Comments

@vincentmele
Copy link

What did you do?

I receive financial market data in JSON format and want to parse it to Decimal, ensuring that there is no loss of fidelity using python's float type.

What did you expect to happen?

The standard json library supports the parse_float parameter in json.loads(). ujson does not appear to have a similar ability.

  • OS: Ubuntu 18.04
  • Python: 3.7.7
  • UltraJSON: 2.0.0-dev4 (but also seen on 1.35)
import json
str_msg = '{"jsonrpc": "2.0","result": {"test1": 935733.817019799357333475932629142801644788893573383506621454627967,"test2": 3383506.81}}'
pprint.pprint( ujson.loads(str_msg))
pprint.pprint( json.loads(str_msg, parse_float=decimal.Decimal))

usjon results in:
{'jsonrpc': '2.0', 'result': {'test1': 935733.8170197994, 'test2': 3383506.81}}

json result in (desired result):
{'jsonrpc': '2.0', 'result': {'test1': Decimal('935733.817019799357333475932629142801644788893573383506621454627967'),'test2':Decimal('3383506.81')}

This may be similar to #124 and #69 but neither relate specifically to decimal.

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

1 participant