JSON to Protobuf (proto3) Generator
Paste a JSON sample and get proto3 message definitions you can compile with protoc or buf. Runs in your browser.
Paste a JSON sample and get proto3 message definitions you can compile with protoc or buf. Runs in your browser.
When you move a JSON API to gRPC or start storing events as Protocol Buffers, the first step is a message definition that matches the data you already have. This JSON to Protobuf converter reads a representative JSON object (or an array of them) and writes proto3 message definitions: one message per object shape, a numbered field per key, and types inferred from the sample values.
message Root; nested objects get their own messages.schema.proto, rename Root to something meaningful, and add a package line.protoc or buf generate.{"userId":7,"name":"Ada","score":9.5,"active":true,"tags":["a"],
"address":{"city":"London"},"orders":[{"sku":"A1","qty":2},{"sku":"B","price":3.5}],
"big":9000000000}
generates
syntax = "proto3";
message Root {
int32 user_id = 1; // json: "userId"
string name = 2;
double score = 3;
bool active = 4;
repeated string tags = 5;
Address address = 6;
repeated Order orders = 7;
int64 big = 8;
}
message Address {
string city = 1;
}
message Order {
string sku = 1;
int32 qty = 2;
double price = 3;
}
Real responses are messier. Here the second order is missing fields the first has, meta is null, labels is empty and matrix is an array of arrays:
[{"orderId":"o-1","createdAt":"2026-10-01T08:00:00Z","items":[{"sku":"A1","qty":2}],
"status":"PAID","meta":null,"matrix":[[1,2],[3]],"labels":[]},
{"orderId":"o-2","total":12.5,"items":[]}]
syntax = "proto3";
import "google/protobuf/struct.proto";
message Root {
string order_id = 1; // json: "orderId"
string created_at = 2; // json: "createdAt"
repeated Item items = 3;
string status = 4;
google.protobuf.Value meta = 5; // null in sample
repeated google.protobuf.ListValue matrix = 6;
repeated string labels = 7; // empty array in sample
double total = 8;
}
message Item {
string sku = 1;
int32 qty = 2;
}
Keys from every element are merged into one message, so total appears even though only the second order has it. The comments flag the guesses: meta had no value to infer from, and labels defaulted to string because the array was empty. A nested array cannot be repeated repeated in protobuf, so matrix uses ListValue; a wrapper message such as message Row { repeated int32 values = 1; } is usually the better fix.
int32, or int64 when the sample value is outside the 32-bit range; numbers with a fraction become double. In an array of numbers, the largest value decides between int32 and int64.orders gives Order, categories gives Category). Name clashes get a number suffix.null becomes google.protobuf.Value and the struct.proto import is added.Field names are converted to snake_case, the protobuf style guide convention, and a // json: comment records the original key whenever it changed. For camelCase keys this round-trips perfectly: proto3's JSON mapping turns user_id back into userId. Other keys do not round-trip, so add an explicit json_name:
// input keys: "2fa-enabled", "HTTPStatus", "e-mail"
bool f_2fa_enabled = 1 [json_name = "2fa-enabled"];
int32 httpstatus = 2 [json_name = "HTTPStatus"];
string e_mail = 3 [json_name = "e-mail"];
Without the option, the JSON name of httpstatus is httpstatus and of e_mail is eMail, so existing JSON clients would silently lose those fields.
createdAt come out as string. Switch to google.protobuf.Timestamp; the JSON mapping still reads and writes the same RFC 3339 text.status with a fixed set of values is better as an enum with an _UNSPECIFIED = 0 first value.int64 values are written as strings ("9000000000"). Clients that expect a number need to handle both.optional where "not set" must differ from 0, "" or false.reserved.Root message for its elements. To send the list itself, add message RootList { repeated Root items = 1; }.If you need a schema for validating JSON rather than a wire format, generate one with the JSON Schema generator. For plain classes straight from JSON without protobuf, use the class generator, JSON to Go or JSON to TypeScript. If your sample has long numeric IDs, read JSON big integer precision first, because the browser rounds them before the type is chosen.
The output is proto3. For proto2, change the syntax line to syntax = "proto2"; and add an optional or required label to every non-repeated field.
Yes. Run protoc --go_out=. --python_out=. schema.proto, or configure buf generate with the plugins for your languages.
The sample value was null, so there was no type to infer. Put a real value in the sample, or replace the type by hand, and remove the struct.proto import if nothing else uses it.
Usually, if they use the proto3 JSON mapping. camelCase keys map back automatically from snake_case fields; for keys with dashes, digits first or acronyms, add json_name options so the names match exactly.
No. The schema is generated in your browser.