archethic-node icon indicating copy to clipboard operation
archethic-node copied to clipboard

Handle scientific format in JSON string

Open Neylix opened this issue 1 year ago • 0 comments

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

Neylix avatar Sep 19 '23 08:09 Neylix