Git Product home page Git Product logo

Comments (4)

jhump avatar jhump commented on July 26, 2024

@Harold2017, looks to me like you are using the tool correctly.

That error message means that, while trying to unmarshal the JSON data into a request, it encountered the start of an object -- the curly brance { -- where it was expecting a string value. It expects string values as keys in an object (i.e. field names) and also for fields whose type in the protobuf source is string or bytes.

I can't help you troubleshoot further without a small repro case that includes the protobuf source for the service and message and a JSON payload that triggers the error.

from grpcurl.

Harold2017 avatar Harold2017 commented on July 26, 2024

@jhump , many thanks!
If i want to accept this request json as string on server side like the following .proto presents:

// reception
message Command {
    string appid = 1;  // sender tag
    string jsonData = 2;  // json string
    string others = 3;
}

do i need to change the reception type to struct jsonData = 2 ?

I will try it later and update to you, thanks!

from grpcurl.

jhump avatar jhump commented on July 26, 2024

@Harold2017, yes, you'd need to import "google/protobuf/struct.proto" and then define the field's type as google.protobuf.Struct. That allows it to represent any JSON object.

As is, defined as a string, you'd need to nest that field's JSON payload into a string. Like so:

{
  "appid": "foo",
  "jsonData": "{ \"nested\": \"json\" }",
  "others": "bar"
}

from grpcurl.

Harold2017 avatar Harold2017 commented on July 26, 2024

@jhump You're right! Many thanks!

from grpcurl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.