About the JSON to Protobuf
Generate a proto3 schema from a JSON sample. Nested objects become messages, arrays become repeated fields, and scalar types are inferred.
Key features
- Generates a proto3 .proto schema from a JSON sample
- Nested objects become nested message types
- Arrays become repeated fields
- Infers string, int64, double and bool
- snake_case field names per the Protobuf style guide
- Sequential field numbers ready for review
From JSON to Protocol Buffers
Protocol Buffers (Protobuf) is Google's compact, typed serialization format, used by gRPC, many microservice architectures, Kafka pipelines and mobile apps. Moving from JSON APIs to Protobuf starts with a .proto schema, and writing one by hand for a large payload is tedious. Paste a representative JSON sample and get a proto3 schema to refine.
Example
{
"id": 1024,
"name": "Ada Lovelace",
"active": true,
"roles": ["admin", "editor"],
"address": { "street": "12 Analytical Way", "city": "London" }
}
syntax = "proto3";
message Root {
int64 id = 1;
string name = 2;
bool active = 3;
repeated string roles = 4;
Address address = 5;
}
message Address {
string street = 1;
string city = 2;
}
Type mapping
| JSON | Protobuf |
|---|---|
| string | string |
| whole number | int64 |
| decimal | double |
| boolean | bool |
| array | repeated T |
| object | nested message |
| null | string (refine manually) |
Checklist before using the schema
- Pick precise integer types:
int32,uint32,sint64, etc. - Use well-known types:
google.protobuf.Timestampfor dates,google.protobuf.Structfor free-form data. - Add enums for fields with a fixed set of string values (e.g. status).
- Review field numbers. Numbers 1–15 take one byte on the wire; give them to the most frequent fields.
- Add a package and options such as
go_packageorjava_package.
Generating code from the schema
protoc --python_out=. --java_out=. schema.proto
or use buf generate with a buf.gen.yaml.
Related tools
Generate Java classes directly with JSON to Java. Inspect the sample's types with JSON Deserialize.
How to use the JSON to Protobuf
- Paste your data into the input box, upload a file, or click Sample to try it out.
- Adjust the options above the editor if you need to (indentation, delimiter, and so on).
- The Protobuf appears instantly in the output panel. Any errors are shown with their line and column.
- Click Copy to copy the result, or Download to save it as a file.