snjypl commented on issue #28103:
URL: https://github.com/apache/airflow/issues/28103#issuecomment-1337789035
@potiuk i was wondering if this could be a solution.
```python
import json
from decimal import Decimal
class JSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Decimal):
return float(obj)
return json.JSONEncoder.default(self, obj)
for i in ["102938.3043847474",1.010001,10,"100","1E-128",1E-128]:
org = Decimal(i)
encoded = json.dumps(org,cls=JSONEncoder)
decoded = json.loads(encoded,parse_float=Decimal)
print(f"{org=}")
print(f"{encoded=}")
print(f"{decoded=}")
print(" "*5)
```
output:
```python
org=Decimal('102938.3043847474')
encoded='102938.3043847474'
decoded=Decimal('102938.3043847474')
org=Decimal('1.01000099999999992661514625069685280323028564453125')
encoded='1.010001'
decoded=Decimal('1.010001')
org=Decimal('10')
encoded='10.0'
decoded=Decimal('10.0')
org=Decimal('100')
encoded='100.0'
decoded=Decimal('100.0')
org=Decimal('1E-128')
encoded='1e-128'
decoded=Decimal('1E-128')
org=Decimal('1.00000000000000005401408859568103309052834145426594802430862986593345890744772751462514653740544965836726232958009946209108101694078484369205457039971496303344480117025912844198468177541980552987602212529712035107713678381275316882208085186144350914663534730232928215257050045129264726062873538499086450376880826074188490792948869056999683380126953125E-128')
encoded='1e-128'
decoded=Decimal('1E-128')
```
there is something similar in airflow uitls
https://github.com/apache/airflow/blob/64deada0babf3ad0ebf8dc4465a14dab6358c659/airflow/utils/json.py#L77-L83
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]