proto3 | JSON | JSON example | Notes |
message | object | <code translate="no" dir="ltr">{"fooBar": v,<wbr> "g": null,<wbr> …}</code> | Generates JSON objects. Message field names are mapped to lowerCamelCase and become JSON object keys. If the <code translate="no" dir="ltr">json_<wbr>name</code> field option is specified, the specified value will be used as the key instead. Parsers accept both the lowerCamelCase name (or the one specified by the <code translate="no" dir="ltr">json_<wbr>name</code> option) and the original proto field name. <code translate="no" dir="ltr">null</code> is an accepted value for all field types and treated as the default value of the corresponding field type. |
enum | string | <code translate="no" dir="ltr">"FOO_<wbr>BAR"</code> | The name of the enum value as specified in proto is used. Parsers accept both enum names and integer values. |
map<K,V> | object | <code translate="no" dir="ltr">{"k": v,<wbr> …}</code> | All keys are converted to strings. |
repeated V | array | <code translate="no" dir="ltr">[v,<wbr> …]</code> | <code translate="no" dir="ltr">null</code> is accepted as the empty list <code translate="no" dir="ltr">[]</code>. |
bool | true, false | <code translate="no" dir="ltr">true,<wbr> false</code> |
string | string | <code translate="no" dir="ltr">"Hello World!"</code> |
bytes | base64 string | <code translate="no" dir="ltr">"YWJjMTIzIT8kKiYoKSctPUB+"</code> | JSON value will be the data encoded as a string using standard base64 encoding with paddings. Either standard or URL-safe base64 encoding with/without paddings are accepted. |
int32, fixed32, uint32 | number | <code translate="no" dir="ltr">1,<wbr> -10,<wbr> 0</code> | JSON value will be a decimal number. Either numbers or strings are accepted. |
int64, fixed64, uint64 | string | <code translate="no" dir="ltr">"1",<wbr> "-10"</code> | JSON value will be a decimal string. Either numbers or strings are accepted. |
float, double | number | <code translate="no" dir="ltr">1.<wbr>1,<wbr> -10.<wbr>0,<wbr> 0,<wbr> "NaN",<wbr> "Infinity"</code> | JSON value will be a number or one of the special string values "NaN", "Infinity", and "-Infinity". Either numbers or strings are accepted. Exponent notation is also accepted. -0 is considered equivalent to 0. |
Any | <code translate="no" dir="ltr">object</code> | <code translate="no" dir="ltr">{"@type": "url",<wbr> "f": v,<wbr> … }</code> | If the <code translate="no" dir="ltr">Any</code> contains a value that has a special JSON mapping, it will be converted as follows: <code translate="no" dir="ltr">{"@type": xxx,<wbr> "value": yyy}</code>. Otherwise, the value will be converted into a JSON object, and the <code translate="no" dir="ltr">"@type"</code> field will be inserted to indicate the actual data type. |
Timestamp | string | <code translate="no" dir="ltr">"1972-01-01T10:00:20.<wbr>021Z"</code> | Uses RFC 3339, where generated output will always be Z-normalized and uses 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. |
Duration | string | <code translate="no" dir="ltr">"1.<wbr>000340012s",<wbr> "1s"</code> | Generated output always contains 0, 3, 6, or 9 fractional digits, depending on required precision, followed by the suffix "s". Accepted are any fractional digits (also none) as long as they fit into nano-seconds precision and the suffix "s" is required. |
Struct | <code translate="no" dir="ltr">object</code> | <code translate="no" dir="ltr">{ … }</code> | Any JSON object. See <code translate="no" dir="ltr">struct.<wbr>proto</code>. |
Wrapper types | various types | <code translate="no" dir="ltr">2,<wbr> "2",<wbr> "foo",<wbr> true,<wbr> "true",<wbr> null,<wbr> 0,<wbr> …</code> | Wrappers use the same representation in JSON as the wrapped primitive type, except that <code translate="no" dir="ltr">null</code> is allowed and preserved during data conversion and transfer. |
FieldMask | string | <code translate="no" dir="ltr">"f.<wbr>fooBar,<wbr>h"</code> | See <code translate="no" dir="ltr">field_<wbr>mask.<wbr>proto</code>. |
ListValue | array | <code translate="no" dir="ltr">[foo,<wbr> bar,<wbr> …]</code> |
Value | value | Any JSON value. Check <a href="/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value">google.protobuf.Value</a> for details. |
NullValue | null | JSON null |
Empty | object | <code translate="no" dir="ltr">{}</code> | An empty JSON object |