[protobuf] Re: why does uint64, fixed64 map to string when converted to JSON

2016-07-21 Thread Shashwat Agarwal
Thanks a lot Jon. I have been dealing with JSON usually in the backend far 
more than with Javascript. 

On Tuesday, July 19, 2016 at 6:28:22 PM UTC+5:30, Jon Skeet wrote:
>
> On Monday, 18 July 2016 18:25:41 UTC+1, Shashwat Agarwal wrote:
>>
>> I was looking at this document: 
>> https://developers.google.com/protocol-buffers/docs/proto3#json and 
>> noticed that int64, fixed64, uint64 are mapped to string when converting to 
>> JSON. Any specific reason why this is done? This deviation breaks a lot of 
>> other JSON parsers and any code in JS that relies on the fact that *int64 
>> are numbers rather than string. 
>>
>
> It's due to the way that all numbers in JSON are basically IEEE-754 64-bit 
> doubles... which means that any 64-bit integers can lose information. Using 
> a string instead, all 64-bit integers can be round-tripped with no loss of 
> information.
>
> Jon
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.


[protobuf] Re: why does uint64, fixed64 map to string when converted to JSON

2016-07-19 Thread 'Jon Skeet' via Protocol Buffers
On Monday, 18 July 2016 18:25:41 UTC+1, Shashwat Agarwal wrote:
>
> I was looking at this document: 
> https://developers.google.com/protocol-buffers/docs/proto3#json and 
> noticed that int64, fixed64, uint64 are mapped to string when converting to 
> JSON. Any specific reason why this is done? This deviation breaks a lot of 
> other JSON parsers and any code in JS that relies on the fact that *int64 
> are numbers rather than string. 
>

It's due to the way that all numbers in JSON are basically IEEE-754 64-bit 
doubles... which means that any 64-bit integers can lose information. Using 
a string instead, all 64-bit integers can be round-tripped with no loss of 
information.

Jon
 

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.