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

JSON interoperability issue #5478

Open
hiiamboris opened this issue Feb 9, 2024 · 6 comments
Open

JSON interoperability issue #5478

hiiamboris opened this issue Feb 9, 2024 · 6 comments
Labels
status.reviewed Ticket has been reviewed and accepted for further processing. type.wish Ticket requests a new feature.

Comments

@hiiamboris
Copy link
Collaborator

Describe the bug

I've encountered some API which sends int64 values in and out unquoted in JSON.

Current JSON codec is incapable of encoding or decoding that data. It reads these values as floats:

>> 1111111111111111111111111111 
== 1.111111111111111e27 

and encoded JSON payload as float or as string is rejected by the server.

The library that does that is standard in Go, so will affect all programs unless they intentionally bother with 32-bit compatibility. RFC does not enforce any restrictions on number digits.

To reproduce

>> load-json {{"orderId":1753829281023862788}}
== #(
    orderId: 1.7538292810238628e18
)
>> to-json load-json {{"orderId":1753829281023862788}}
== {{"orderId":1.753829281023863e18}}

Expected behavior

We need a 64 bit integer type, or a set of kludges to pass such values around.

Platform version
Red 0.6.4 for Windows built 4-Feb-2024/4:57:33+03:00 commit #9b8169f

@dockimbel
Copy link
Member

Such long ints could be detected while parsing by the JSON coded and then encoded on the Red side using specific syntax. Maybe @rebolek can confirm the feasibility.

It's unlikely we will implement 64-bit integer separately, as it would require many deep changes in the current toolchain. You'll need to wait for the new toolchain in Red.

@dockimbel dockimbel added type.wish Ticket requests a new feature. status.reviewed Ticket has been reviewed and accepted for further processing. labels Feb 11, 2024
@hiiamboris
Copy link
Collaborator Author

Parsing is not as big problem as encoding, because the codec needs to tell the value apart from the string, meaning we would have to pass it as an issue or ref or smth, which would be a weird kludge.

@dockimbel
Copy link
Member

Could it be encoded as a binary! value or is that type already used by the codec?

@hiiamboris
Copy link
Collaborator Author

hiiamboris commented Feb 11, 2024

Possibly. Currently it just forms binary in a json string:

>> to-json #{aabbcc} 
== {"#{AABBCC}"} 

@greggirwin
Copy link
Contributor

  1. We don't want to design it based on compatibility with this one library.
  2. There is only one number type in JSON, so if they don't handle it correctly, that's on them.
  3. If there are conversion errors, because it becomes a float, that's a problem.
  4. What types of values are represented by the int64?

Money also becomes a string. Percents become a float.

@hiiamboris
Copy link
Collaborator Author

1-2. Like said above, by RFC you can have infinite precision numbers in JSON and it will be compliant.
4. Order ids and timestamps in millisecs.

money! type for it sounds best IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status.reviewed Ticket has been reviewed and accepted for further processing. type.wish Ticket requests a new feature.
Projects
None yet
Development

No branches or pull requests

3 participants