There is actually a new proto type designed to parse/represent arbitrary
JSON data:
https://github.com/google/protobuf/blob/master/src/google/protobuf/struct.proto#L63

So you can define your proto as:

message MyObject {
    string key1 = 1;
    int32 key2 = 2;
    google.protobuf.ListValue key3 = 3;
}

and then you should be able to parse two-dimensional string arrays. There
are two problems though:
1. It not only allows two-dimensional string array, but also allows any
arbitrary JSON array data. For example, it will happily accept "[1, false,
null, {\"a\": 2}]". That is, you lose the ability to do strict type
checking.
2. go jsonpb does not support this new type yet, and if you want to use it,
you probably need to add the support yourself (it's not on go-team's plan
for Q4 as far as I know).

On Tue, Sep 27, 2016 at 12:26 PM, Kostiantyn Shchepanovskyi <
schepanov...@gmail.com> wrote:

> There is no way to workaround this. "key3" looks like a two-dimensional
> string array - it is not supported by protobuf.
>
> On Monday, September 26, 2016 at 8:56:12 PM UTC+3, Michael Leonard wrote:
>>
>> Hi
>>
>> I'm developing a golang server that will receive json in the following
>> format. I can't work out how to write the description of this in a proto
>> file and am hoping someone could help me! Thanks a lot in advance.
>>
>> {
>>     "key1": "asdfwefa",
>>     "key2": 13431,
>>     "key3": [
>>       [
>>         "asdfasdf",
>>         "cdcasdec",
>>         "dareceae"
>>       ],
>>       [
>>         "ggeqsase",
>>         "asdfdfgg",
>>         "asdreavf"
>>       ]
>>     ]
>>  }
>>
>> The problem is the double array and the fact that the strings inside the
>> array don't have named keys. I want to use something like following, but
>> I'm not sure if there's a way to do this:
>>
>> message MyObject {
>>     string key1 = 1;
>>     int32 key2 = 2;
>>     repeated Key3 key3 = 3;
>> }
>>
>> message Key3 {
>>     repeated ...???...
>> }
>>
>>
>> Please note:
>> - I'm using proto3 syntax in my application in case that's important
>> information.
>> - I can't modify the json format before it hits my golang server. However
>> I could modify it when it arrives (somehow? perhaps marshal to a golang
>> struct first, or modify the text string somehow - any easy solutions would
>> be appreciated?) and then marshal it using the golang jsonpb package.
>>
>>
>> Thanks for any help
>>
>> Mike
>>
>>
>> --
> 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.
>

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

Reply via email to