grpcurl icon indicating copy to clipboard operation
grpcurl copied to clipboard

Un-quoted integer response values

Open lukaskollmer opened this issue 3 years ago • 1 comments

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?

lukaskollmer avatar Dec 02 '21 22:12 lukaskollmer

@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.

jhump avatar Dec 08 '21 03:12 jhump