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.

From a JSON payload to a .proto file

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.

How to use it

  1. Paste a JSON object, or an array of objects, into Input. A bare string, number or array of scalars is rejected because there is no message to build.
  2. Click Run Tool. The top-level object becomes message Root; nested objects get their own messages.
  3. Copy the output into a file such as schema.proto, rename Root to something meaningful, and add a package line.
  4. Review the types using the checklist below, then compile with protoc or buf generate.

Example 1: a user with nested data

{"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;
}

Example 2: an array of orders with gaps and nulls

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.

How types are chosen

Field names and the proto3 JSON mapping

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.

Before you ship the schema

Related tools

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.

Frequently asked questions

Does it support proto2?

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.

Can I generate code from the .proto?

Yes. Run protoc --go_out=. --python_out=. schema.proto, or configure buf generate with the plugins for your languages.

Why is a field typed google.protobuf.Value?

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.

Will my existing JSON clients still work after switching to protobuf?

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.

Is my JSON uploaded?

No. The schema is generated in your browser.