A reference for what a field can hold. Scalar types map directly to standard primitives in your programming language, well-known types cover common structures like timestamps, and every type has a defined JSON representation.
Numeric Types
Other Scalar Types
Well-Known Types (WKTs) are schemas standardized by Google, with dedicated JSON mappings for clean integration with web APIs. Every WKT ships with every compiler, so you can import them without declaring a dependency. Full definitions are in the google.protobuf reference.
General
Dynamic JSON
Like every well-known type, these are ordinary messages defined in plain .proto files you can read: struct.proto defines Struct and Value, and wrappers.proto defines the wrapper types, which are rarely needed now that optional provides explicit presence.
One more family of WKTs describes APIs and types themselves, powering runtime reflection and API tooling; they rarely appear in hand-written schemas. The most interesting are Method in api.proto, Type in type.proto, and SourceContext in source_context.proto.
While Protobuf is primarily binary, it defines a canonical ProtoJSON mapping. This ensures that every binary payload has a deterministic representation in JSON.
| Protobuf Type | JSON Type(s) | JSON Value Example | Notes |
|---|---|---|---|
message | JSONObject | Example{"userName": "hiro"} | Serialized as a JSON object. Field names are mapped to lowerCamelCase by default, or the json_name option if set. |
repeated | JSONArray | Example["a", "b"] | Serialized as a JSON array. |
map<K, V> | JSONObject | Example{"k": "v"} | Serialized as a JSON object. |
int32, uint32 | JSONNumber | Example42 | Standard JSON numbers. |
float, double | JSONNumber | Example123.45 | Standard JSON numbers. |
bool | JSONBoolean | Exampletrue | Standard JSON booleans. |
int64, uint64 | JSONString | Example"9007199254740993" | Strings prevent precision loss in JS. |
enum | JSONString | Example"ROLE_ADMIN" | Uses the string name of the enum value. |
bytes | JSONString | Example"NDI=" | Base64 encoded string. |
google.protobuf.Timestamp | JSONString | Example"2023-10-01T12:00:00Z" | RFC 3339 formatted timestamp string. |
google.protobuf.Duration | JSONString | Example"1.000340012s" | Seconds with up to 9 fractional digits. |
google.protobuf.FieldMask | JSONString | Example"f.a,f.b" | Comma-separated paths as a single string. |
google.protobuf.Struct | JSONObject | Example{"foo": "bar"} | Standard representation for a generic JSON object. |
google.protobuf.Value | JSONAny | Example"foo" or 123 | Can be any valid JSON value (null, number, string, boolean, struct, or list). |
google.protobuf.NullValue | JSONnull | Examplenull | The JSON null value. |
google.protobuf.Empty | JSONObject | Example{} | An empty JSON object. |
64-bit Precision
JavaScript numbers are 64-bit floats, which lose precision for integers above 253 - 1.
To prevent data loss, 64-bit integer types (int64, fixed64, uint64, sint64, and sfixed64) are encoded as strings in JSON.