JSON to Protobuf
Convert a JSON sample to a Protocol Buffers (proto3) message definition.
JSON Size
0 B
JSON Lines
0
Proto Messages
0
Proto Lines
0
About JSON to Protobuf
This tool converts a JSON object sample into a Protocol Buffers (proto3) schema. It automatically maps JSON types to proto types — strings stay string, integers become int64, floats become double, and booleans become bool. Arrays of primitives are emitted as repeated fields; nested objects and arrays of objects generate their own named messages. All dependency messages are declared before the messages that reference them, so the output drops straight into a .proto file ready for protoc or any gRPC framework. Everything runs in your browser — nothing is sent to a server.
Built and maintained by Meet Shah · Last updated
What this tool is used for
- Generating a proto3 message definition from a sample payload.
- Producing a starting schema for a service with no contract.
- Seeing how nested objects map onto nested messages.
- Creating a definition for a fixture that matches production shapes.
- Comparing a generated definition against an existing one.
Frequently Asked Questions
- What is a field number and why does it matter more than the name?
- It is the identity of the field on the wire. Protobuf encodes the NUMBER, not the name, so renaming a field is a compatible change while renumbering one silently reinterprets old data as a different field. Numbers 1–15 use a single byte for their tag, so give those to the fields that appear most.
- Why is everything optional in proto3?
- Because proto3 removed required fields deliberately: a required field can never be removed without breaking every old reader, which turned out to be a versioning trap rather than a safety feature. A missing scalar simply arrives as its zero value — 0, empty string, false.
- How does it know a field should be repeated?
- From the JSON array. `["admin", "user"]` becomes `repeated string tags`, taking the element type from the contents. An empty array carries no type information at all, so it cannot be inferred — that is a case to fix by hand rather than trust.
- Why does 98.5 become a double rather than a float?
- Because JSON numbers are IEEE-754 doubles and narrowing to `float` would lose precision silently. `double` is the honest translation; switch to `float` deliberately if you know the range fits and the payload size matters, not by default.
- Can I get the JSON back out of protobuf?
- Yes — the protobuf JSON mapping is well defined, converting snake_case field names to lowerCamelCase by default. But it is not a byte-for-byte round trip: field order is not preserved, and a field left at its default value is omitted entirely unless you ask for defaults to be emitted.
Common errors and gotchas
- Accepting the generated field numbers, which become a wire-compatibility commitment once shipped.
- Letting a whole number become `int32` when the values exceed its range.
- Losing the distinction between an absent field and a zero value, which proto3 handles specifically.
- Generating a `map` where a repeated message was intended, or the reverse.
- Assuming field names convert cleanly, when proto has its own naming conventions.