Use a small schema to test each type.
Load this definition into the schema workspace. The matching JSON uses a decimal string for the large integer, an enum name, Base64 for bytes and a single member of the oneof.
syntax = "proto3";
message Record {
int64 record_id = 1;
enum State { UNKNOWN = 0; READY = 1; }
State state = 2;
bytes data = 3;
oneof contact {
string email = 4;
string phone = 5;
}
}Preserve the value, not just the appearance.
The integer 9007199254740993 is larger than JavaScript can represent exactly as a Number. Quotes keep its decimal digits intact until the Protobuf encoder converts them into a 64-bit integer.
{
"record_id": "9007199254740993",
"state": "READY",
"data": "SGk=",
"email": "dev@example.com"
}Check the mapping for each field.
| Protobuf type | JSON in this workspace | Watch for |
|---|---|---|
| int64 / uint64 | Decimal string, or a safe integer number | Quoted strings preserve large values; signed and unsigned ranges differ. |
| enum | Declared name or an int32 numeric value | Unknown names are rejected; numeric values can preserve newer sender values. |
| bytes | Padded Base64 string | SGk= represents the bytes 48 69, not the literal characters S G k =. |
| repeated | JSON array | Each entry must match the element type. |
| map | JSON object | Keys are strings in JSON, including decimal 64-bit keys. |
| oneof | One member at a time | Remove the old member before setting a different one. |
Know which JSON format you are using.
The official ProtoJSON format normally prints field names in lowerCamelCase and represents 64-bit integers as strings. This workspace uses protobufjs with keepCase enabled, so input and output retain the field spelling in your .proto file: record_id remains record_id.
Decoded output includes default values and may include a oneof discriminator such as "contact":"email". The workspace accepts that discriminator when it agrees with the populated member. These are workspace conventions, not a promise of full canonical ProtoJSON compatibility.
A displayed zero or empty string does not always mean that a sender explicitly set the field. Presence depends on the declaration, including optional and oneof. Consult your schema before treating default-filled JSON as a presence report.
Fix the input rather than coercing it.
- Do not turn large int64 strings into Number values while editing.
- Use a boolean true or false for bool fields, not quoted text.
- Use a numeric JSON value for int32 fields; the workspace rejects numeric strings there.
- Do not populate both email and phone in the example oneof.
- Keep the original binary when unknown fields or exact original serialization must be retained; converting through JSON can discard information.
Reference material
Use the specifications for details beyond these examples.