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

Support to convert int json to value #671

Open
rohitjangid opened this issue Mar 15, 2023 · 2 comments
Open

Support to convert int json to value #671

rohitjangid opened this issue Mar 15, 2023 · 2 comments

Comments

@rohitjangid
Copy link
Contributor

Hi

I was creating a native function which returns an int64 value and faced following error:

RUNTIME ERROR: Not a json type: 1234567890

After debugging this further, I found that we do not support converting int64 json to value (https://github.com/google/go-jsonnet/blob/master/interpreter.go#L934). Is there any reason we are not supporting int and int64 values? If not, I am happy to implement it.

@sparkprime
Copy link
Member

Typically JSON does not support large integers - it supports doubles so it can go to a certain size of integer while keeping integer precision. That size is usually enough for everyone. In the Google Cloud APIs this is worked around by using a string to represent large numbers.

@sbarzowski
Copy link
Collaborator

You can encode it as float64. This is lossless for numbers up to 2^53-1. We don't support larger numbers – we simplify things by having only one number type and as Dave mentioned you cannot count on all JSON parsers handling bigger integers precisely anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants