archethic-foundation / archethic-foundation/archethic-node
Handle scientific format in JSON string
- Dominant language
- Elixir
- Stars
- 82
- Forks
- 24
- PR merge metrics
- No merged PRs in 30d
Description
### 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 after `Jason.decode` will be a float `1435000000.0` and not an integer `1435000000`. 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` the `Jason.encode` will produce a string with a scientific format `1.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_
Contributor guide
Research direction
Start by tracing the Jason.decode and Jason.encode call sites involved in API payloads and inspect how decoded maps are converted to structs. Define completion as preserving the intended integer or float values during decoding and avoiding scientific notation during encoding, with coverage for both examples in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100