The fundamental unit for protobufs (across all serialization and 
presentation formats, including JSON) is a message.

The semantics of the general JSON format do not map to protobuf semantics 
very well, but the proto3 language guide has a section on the JSON 
structures that can interoperate with protobufs:
https://developers.google.com/protocol-buffers/docs/proto3#json

The impetus for JSON interop is for servers which can understand either 
JSON- or wire-formatted requests, so a top-level list would pretty 
fundamentally break semantics. Given that pitfall, it's pretty unlikely 
that we would add support for anything other than a top-level message. The 
example you gave is how I would recommend representing "just" a list.

On Wednesday, April 22, 2020 at 5:18:24 PM UTC-7, Guilherme Costa wrote:
>
> I have a question regarding Protobufs, since I want to generate an array 
> of JSONs by using them, such as in this example
>
>> [
>>    {
>>     "var": ["myVariable1","myVariable2"], 
>>     "key1": 123123,
>>     "key2": 1122,
>>     "key3": "abcd-0101"
>>    },
>>   { 
>>     "var": ["myVariable1"], 
>>     "key1": 123124,
>>     "key2": 1123,
>>     "key3": "abcd-0102"
>>   },] 
>>
>>
> However, I just can get the example below:
>
>> {
>>  list: [
>>    {
>>     "var": ["myVariable1","myVariable2"], 
>>     "key1": 123123,
>>     "key2": 1122,
>>     "key3": "abcd-0101"
>>    },
>>   { 
>>     "var": ["myVariable1"], 
>>     "key1": 123124,
>>     "key2": 1123,
>>     "key3": "abcd-0102"
>>   },]  
>>
>> }
>>
>>
> It is possible to generate the first example (without the brackets and the 
> first key) using protobufs?
> Some of this issue are also discussed in: 
> https://stackoverflow.com/questions/46945555/how-to-model-json-array-as-protobuf-definition,
>  
> they also had the same question, but I tried and did not work at all!
>
>
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/protobuf/8a095f8d-a572-41fb-8fb7-72de6208874e%40googlegroups.com.

Reply via email to