fullstorydev / grpcurl

Like cURL, but for gRPC: Command-line tool for interacting with gRPC servers
MIT License
10.94k stars 507 forks source link

Un-quoted integer response values #272

Open lukaskollmer opened 2 years ago

lukaskollmer commented 2 years ago

When making a request to a gRPC method returning a message that contains an integer, the JSON structure printed to stdout wraps these numbers in double quoues.

E.g.:

> grpcurl localhost:50051 Service.Method
{
  "value": "12"
}

The same also applies to repeated integers, in which case the output would be e.g. { "value": ["1", "2", "3"] }, despite value, in this example, being a repeated int64.

Is there a reason for this behaviour? Is it possible to disable it, i.e. to tell grpcurl to format them as unqouted numbers?

jhump commented 2 years ago

@lukaskollmer, that is the encoding for protos in JSON format: https://developers.google.com/protocol-buffers/docs/proto3#json

64-bit ints are formatted as strings, but accepted as either strings or numbers. The reason is that JS runtimes use a 64-bit floating point representation for numbers, which cannot accurately represent all integers above 2^53.