Protocol Buffers Formatter parses and pretty-prints .proto schema files and protobuf JSON/binary data. Paste a Protocol Buffers schema definition to format it with consistent indentation and alignment, or paste protobuf JSON (the JSON encoding of a protobuf message) to validate and format it. Use this to clean up generated .proto files or debug protobuf message structures.
Protocol Buffers (protobuf) is Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data — like JSON or XML, but smaller (binary format), faster, and strongly typed. A .proto file defines the schema: messages (like structs), fields with types and field numbers, services (RPC definitions), and enums. The protoc compiler generates code in your target language (Go, Python, TypeScript, Java, C++) from the .proto schema.
Protobuf wire format uses field numbers (not field names) to identify fields, which makes the binary format extremely compact. Field numbers are permanent — changing a field number breaks compatibility with existing encoded data. Adding new fields with new numbers is backward compatible. Removing fields should use reserved to prevent future reuse of the number. Proto3 (the current version) doesn't support required fields — all fields are optional with zero/empty defaults.
Format proto schema
Result: message User {\n int64 id = 1;\n string name = 2;\n repeated string emails = 3;\n}
Validate field numbers
Result: field 'id = 1' ✓, field 'name = 2' ✓ — no duplicate or reserved field numbers
gRPC service definition
Result: service UserService { rpc GetUser (GetUserRequest) returns (User); }
What are protobuf field numbers and why do they matter?
Each field in a protobuf message has a field number (e.g., id = 1) that identifies the field in the binary wire format. Field names are stripped — only numbers are encoded. This is why protobuf is compact. Field numbers are permanent: once a .proto file is deployed and data is encoded, you can never change a field's number — any existing encoded data will misinterpret the field. Safe changes: add new fields with new numbers; remove fields (use reserved to block reuse). Breaking changes: renumbering fields, changing field types incompatibly.
What is the difference between proto2 and proto3?
Proto2 (2008): supports required and optional field labels; explicit defaults; extensions. Proto3 (2016, current): removed required (all fields optional with language defaults); simplified defaults (zero values); added map fields; JSON mapping; better support for dynamic messages. Proto3 is recommended for new projects. Key proto3 change: there's no way to distinguish a field set to its zero value (0, '', false) from a field that wasn't set at all — proto3 uses wrappers (google.protobuf.Int64Value) if you need this distinction.
How does protobuf compare to JSON for performance?
Protobuf binary encoding is typically 3-10x smaller than JSON for the same data, and 2-5x faster to parse. Why smaller: field numbers instead of field names (key 'user_id' → field 1), binary encoding of numbers (int64 in fixed 8 bytes or varint encoding), no delimiters between fields. Why faster: parsing doesn't require a lexer (no JSON string escaping), generated code is strongly typed. Tradeoffs: protobuf binary is not human-readable (you need the .proto schema to interpret it), debugging requires extra tooling, not supported by all HTTP clients without a library.
What is gRPC?
gRPC is a high-performance RPC (Remote Procedure Call) framework by Google that uses Protocol Buffers for serialization and HTTP/2 for transport. You define services and their RPC methods in a .proto file, run protoc to generate client and server stubs, implement the server logic, and use the generated client to make strongly-typed RPC calls from any supported language. Key features: bidirectional streaming (HTTP/2), code generation for 10+ languages, built-in authentication/interceptors, load balancing. gRPC is widely used in microservices (Google, Netflix, Cloudflare).
How do I convert protobuf to JSON?
Protobuf has an official JSON mapping (Proto3 JSON Mapping in the protobuf docs). Field names are converted to camelCase in JSON. Repeated fields become JSON arrays. Bytes fields are base64-encoded. Well-known types (Timestamp, Duration, etc.) have special JSON representations. In code: Java: JsonFormat.printer().print(message). Python: MessageToJson(message). Go: protojson.Marshal(message). JavaScript: protobuf.js has toObject() / JSON.stringify(). Most gRPC frameworks support 'grpc-transcoding' to expose gRPC services as REST/JSON automatically.