> ## Content Index
> Fetch the complete content index at: https://datajutsu.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# A Protobuf Optional Is the One Field the JSON Refuses to Fill (and the Bytes Never Change)
- URL: https://datajutsu.com/protobuf-optional-presence/
- Published: 2026-10-24T03:42:49.000Z
- Updated: 2026-10-24T03:42:49.000Z
- Author: Data Jutsu

I took a proto3 message, put the word optional in front of one of its fields, and watched what actually changes. The answer is small and it lives almost nowhere you would look. The bytes are the same, the encoder writes the same bytes, and the only things that move are a line in the file descriptor, an object the parser builds that you never asked for, and, the part that matters for a tool, whether the JSON your decoder prints contains the field at all.

The wire does not know the word. I made two messages that are identical except one declares optional int32 opt = 2 and the other declares the same field as a bare int32 opt = 2, and held the same value in both. They encode to the same bytes, 08051007 for plain 5 and opt 7\. A zero is 08051000 in both, a field that was never set is nothing in both, and I could not find a case where the two write different bytes on the way out. The keyword is not a wire feature. It is a label in the schema file, and the stream never reads it, which is the same shape as the proto2 required post found, the word is a check and the bytes carry no trace of it.

The descriptor is where the keyword costs something, and I checked it against the real protoc 25.3 binary. The file with the keyword is thirteen bytes larger than the one without, seventy seven against sixty four, and the whole difference is a oneof. The parser wraps the field in a one-member group it names after the field, with an underscore in front, and tags it proto3\_optional. You never declared a oneof. It is the mechanism the format uses to remember that this is a field you asked about, and it is the same machinery the oneof post covers, hidden under a name you did not pick.

This is the part that lands in a tool, so I ran the tool's own decode path, the one that fills unset fields with their type defaults, the cleaner view. A bare proto3 field that was never on the wire comes out filled: the int32 prints as zero, the string prints as an empty string, and you cannot tell a sender who sent a zero from a sender who sent nothing, because both print the same thing. The explicit-optional field is different. It is a member of that hidden oneof, and oneof members are the one thing the default fill skips, so a field that was never written stays out of the JSON entirely. Same absent field, same decoder, two different outputs, and the only difference is the keyword. That is the whole point of the word in a browser, it is the marker that lets the read side say written versus not.

Two more facts I measured while I was in there. First, the hidden oneof is not fully hidden. The decode output carries a selector key named for it, \_opt, and it is present exactly when the field was on the wire and gone when it was not. That key is, in practice, the has-method the format is supposed to give you, and it is a leftover of the oneof machinery rather than a clean API, the closest the output gets to a was-this-written flag. Second, the decoded instance in this build has no has method at all, the prototype only carries the fields and the selector. The presence check you would write by hand is whether the object has its own key for the field, which is exactly what that selector is tracking, so the format's has-method and the library's have-method are two different things and the library one is the one you can actually call.

Where it lands for a change. If you are trying to tell the client sent a zero from the client sent nothing in proto3, optional is the only lever, and it works by making the field invisible by absence in the default view instead of visible by default. The wire pays zero, the schema pays thirteen bytes and a hidden oneof, and the JSON is the place you actually see it. The two-syntax history it sits in is in the [proto3 versus proto2 post](https://datajutsu.com/proto3-vs-proto2/), the oneof machinery under the keyword is in the [oneof post](https://datajutsu.com/protobuf-oneof/), and the other presence mechanism, a field that can hold zero, is in the [wrapper types post](https://datajutsu.com/protobuf-wrapper-types/). The tool at [proto.datajutsu.com](https://proto.datajutsu.com/?ref=datajutsu.com) runs the fill-on decode view, so paste a proto3 message with an optional field, decode bytes where it was and was not, and watch one field appear and disappear while the bytes it would have carried are unchanged.