12

I want to define a request message in gRPC which should have a Json Object as a field For e.g.

message UserRequest{
    string name = 1;
    string city = 2;
    string email = 3;
    metainfo = 4;//A Json Object variable which can have any number of elements
}

How do I represent the metainfo property within proto definition? I have tried using below definition but it didn't work.

message UserRequest{
    string name = 1;
    string city = 2;
    string email = 3;
    google.protobuf.Any metainfo = 4;
}
pranay jain
  • 352
  • 1
  • 2
  • 15

1 Answers1

14

I think you want a .google.protobuf.Struct, via struct.proto - this essentially encapsulates a map<string, Value> fields, and is broadly akin to what you would want to describe via JSON. Additionally, Struct has custom JSON handling, as mentioned in the file:

The JSON representation for Struct is JSON object.

So:

    .google.protobuf.Struct metainfo = 4;
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900