Loading Proto File Formatter...
Please wait a moment

How to Format a .proto File

A .proto file that came out of a code generator, a chat message or a quick edit often ends up on one long line or with indentation that no longer matches the nesting. This page lays it out again the way the protobuf style guide describes, without touching a single name, number or comment.

Step 1

Paste or upload the .proto file

Paste a whole .proto file or just a few messages into the left editor, upload a .proto file (up to 10 MB), or press Sample to load a schema that was squashed onto one line.

Example: a schema squashed onto a few lines

syntax="proto3";package shop.v1;import "google/protobuf/timestamp.proto";
// An order as stored in the billing system
message Order{int64 id=1;string sku=2 [json_name="itemCode"];double price=3;google.protobuf.Timestamp placed_at=4;map<string,string> labels=5;enum Status{STATUS_UNSPECIFIED=0;STATUS_PAID=1;}Status status=6;}
service OrderService{rpc GetOrder(GetOrderRequest)returns(Order);}
message GetOrderRequest{int64 id=1;}
Step 2

Read the formatted schema

A moment after you stop typing, the right panel shows the file with 2-space indentation, one field or option per line and a blank line between top-level messages, enums and services. If the file has a mistake, such as an unclosed string or a missing semicolon, you get the line and column instead.

The same schema after formatting

The comment still sits right above message Order, so it remains that message's doc comment, and the nested enum is indented one level deeper than the fields around it.

syntax = "proto3";

package shop.v1;

import "google/protobuf/timestamp.proto";

// An order as stored in the billing system
message Order {
  int64 id = 1;
  string sku = 2 [json_name = "itemCode"];
  double price = 3;
  google.protobuf.Timestamp placed_at = 4;
  map<string, string> labels = 5;
  enum Status {
    STATUS_UNSPECIFIED = 0;
    STATUS_PAID = 1;
  }
  Status status = 6;
}

service OrderService {
  rpc GetOrder(GetOrderRequest) returns (Order);
}

message GetOrderRequest {
  int64 id = 1;
}
Step 3

Copy or download it

Copy puts the formatted file on your clipboard; Download saves it as formatted.proto. Both use exactly what you see in the right panel.

Want to check the schema itself rather than its layout? The Proto File Validator looks for problems, and JSON to Protobuf writes a .proto schema from a sample JSON document.

Why bother formatting .proto files?

A .proto file is the contract between services, so people read it far more often than they edit it. When every message is indented the same way and every field sits on its own line, a reviewer can see at a glance which message a field belongs to and spot a reused field number.

Consistent layout also keeps diffs small: if everyone on a team formats the same way, a pull request that adds one field changes one line instead of reshuffling the whole message. For gRPC projects the service definitions in the same file benefit in the same way.

Frequently Asked Questions

Can formatting change what protoc generates from my file?

No. Only the spaces, line breaks and indentation between tokens change. Names, field numbers, strings and option values such as 8901240544102066246, "00501" or 14.50 are copied character for character, and so are your comments. Before the result is shown, the page reads it again and checks that it holds exactly the same tokens as your input. If you want to double-check, compile both files with protoc --descriptor_set_out: the two descriptor sets are identical.

What layout does the formatter use?

It follows the layout from the protobuf style guide: two spaces per nesting level, one statement per line, the opening brace on the same line as message, enum or service, and spaces around = in fields and options. It writes map<string, int32> and rpc GetUser(GetUserRequest) returns (User); and puts a blank line between top-level definitions and between the syntax, package, import and option groups. It does not rename anything, sort imports, renumber fields or line up the = signs.

What happens to my comments?

They are kept word for word. A comment on the line above a field or message stays directly above it, so protoc still treats it as the doc comment that ends up in the generated code. A comment at the end of a line stays at the end of that line, and blank lines you left between sections are kept (several in a row become one).

Which mistakes does it point out?

Strings or /* comments that are never closed, braces and brackets that do not pair up, characters a .proto file cannot contain, a missing semicolon or = sign, misspelled keywords and a name used twice in the same message. Each message gives the line and, where it can, the column. It is a formatter, not a compiler: it does not check that imported files and referenced message types exist or that field numbers are unique, so protoc still has the last word.

Does it work with proto2, proto3 and editions?

Yes. Files with syntax = "proto2", syntax = "proto3" or edition = "2023" are all handled, including groups, extensions and extend blocks, oneof, map fields, streaming RPCs, reserved ranges and custom options. Option values written in text format, such as option (my_opt) = { a: 1 b: "x" };, are kept on one line. A snippet without a syntax line is fine too.

Is my .proto file uploaded anywhere?

No. Formatting runs in your browser and the file is not sent to our server. Nothing is kept either: when you reload the page, the editor starts empty.