archethic-node
archethic-node copied to clipboard
Handle scientific format in JSON string
Is your feature request related to a problem?
Currently we use Jason module to decode en encode JSON strings. This module works well in many case but have some unwanted behavior with big number. For example:
- If the JSON string contains a scientific format
1.435e9
the resulting number afterJason.decode
will be a float1435000000.0
and not an integer1435000000
. This is correct but create error after since some API expect to have an integer. - In the other way, if we have a big float number
1435000000.0
theJason.encode
will produce a string with a scientific format1.435e9
which could create issue.
Describe the solution you'd like
There is 2 things to cover these issues:
- For any API or JSON string we decode, we should have a second step to cast the result map into a struct. This will ensure that all field have the correct value when used afterward. It will also make the code more clean, understansable and reduce the risk of error.
- We could create a new implementation of the
Jason.encode
protocol for float number, to not convert them in scientific format.
Additional context
No response
Epic
No response