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

The format is wrong when output int_64 to JSON.. #4103

Closed
imkcy9 opened this issue Dec 27, 2017 · 2 comments
Closed

The format is wrong when output int_64 to JSON.. #4103

imkcy9 opened this issue Dec 27, 2017 · 2 comments

Comments

@imkcy9
Copy link

imkcy9 commented Dec 27, 2017

When I use MessageToJson function serializing "int64 n" to JSON, the value of n is 40, it should output like {"n":40 }, but the fact is output like {"n":"40"}, how to fix it ??

@trianta2
Copy link

I believe this is the line that causes the unexpected output.

This may be a bandaid fix due to a limitation in JavaScript, i.e. it doesn't have support for 64 bit integers, only doubles. Perhaps preserving the original value as a string allows the module to decode it correctly.

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Feb 20, 2018

JSON implementations may not support 64-bit integers so to guarantee the value can be round-tripped we print 64-bit integers as strings. If you are consuming the proto JSON output directly, make sure you are doing it in accordance with the proto3 JSON mapping here:

https://developers.google.com/protocol-buffers/docs/proto3#json

Specifically you should accept both numbers and strings for 64-bit proto fields.

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