> ## 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.

# When Your JSON Does Not Match the Schema, the Protobuf Encoder Mostly Does Not Care
- URL: https://datajutsu.com/protobuf-json-encode-mismatch/
- Published: 2026-10-24T15:21:16.000Z
- Updated: 2026-10-24T15:21:16.000Z
- Author: Data Jutsu

I fed a message schema a batch of JSON that did not match it, and I expected an error. I got bytes. That was the surprising part, and it took me a while to pin down where the encoder actually says no, because the answer is small. It says no in four places, and for everything else it either converts the value or quietly drops the field and moves on. So the mental model is not the encoder is a validator. It is the encoder is permissive, and permissive in a way that will hand you the wrong bytes instead of the error you wanted.

The four doors that are loud are all about shape. Put a value where a message should be, a plain number or a string, and it throws object expected. Put a bare value where a repeated field should be, and it throws array expected. Put a non-object where a map field should be, same object expected. And put a string at a bytes position that is not valid base64, and it throws invalid encoding, because the string is read as base64, the same encoding the JSON mapping uses for bytes, so the check is real. Those are the only failures I could find, and none of them are about the type of a scalar. Everything inside a correctly shaped container is fair game for the permissive part of the machine.

So what is permissive, and I measured it across every declared type. A string handed to an integer becomes a number, and a string that is not a clean number becomes zero. A float becomes an integer by truncation. A true becomes a one. A negative one into an unsigned thirty two bit field wraps to four billion two hundred ninety four million nine hundred sixty seven thousand two hundred ninety five, with no complaint. A string that is not a number into a double becomes NaN, and NaN is real bytes on the wire, the eight byte NaN pattern, not an empty field. A false handed to a bool becomes true, because the rule is any non-empty string is true, and the string is not empty. The most dangerous one for a tool is the sixty four bit integer, a decimal string that is not a valid number becomes zero, and a decimal string that is a valid big number survives as the exact full length varint the format uses for big sixty four bit values, which is what the int64 precision work landed last week made possible.

Then there is the part that is neither loud nor a conversion, the field that simply vanishes. A null at any scalar position removes the field from the output, zero bytes, no error. An enum value spelled as a name that is not a member also vanishes the field, no error, and it is worth the contrast: the same enum handed a number that is not a member writes that unknown number to the wire as a raw varint and it reads straight back, so a bad name erases the field and a bad number survives it. A bytes field handed a number or a null also vanishes, which is its own little trap, because the natural thing to type into a bytes field is a number. And the bytes field has one more twist: a string is not taken letter by letter, it is read as base64, the same encoding the JSON mapping uses for bytes, so the two letters hi decode to a single byte, one hundred thirty four, which is almost certainly not the bytes you meant to send. And a field you never declared in the schema, at the top level or nested or inside a repeated item, is stripped from the object before the bytes are written. None of these are errors. They are the encoder doing the quiet thing, and the quiet thing is the one that produces a message that looks right and means something else.

The one that undoes the intuition that a schema is a wall is the oneof. Set both members of a oneof in the same object, and the encoder writes both of them to the wire, tag and value for each, no error that a oneof should only hold one. The schema says pick one, the encoder says you may have both, and the decoder on the far end gets to decide what that means. That is the whole post in one line, the encoder enforces the container shape and lets the rest through, so a JSON that does not match your schema usually becomes bytes. The decode side of this, where a valid wire becomes the JSON you read, is in the [JSON mapping post](https://datajutsu.com/protobuf-json-mapping/), the catalog of the decode direction errors is in the [conversion errors post](https://datajutsu.com/protobuf-json-conversion-errors/), and the tool at [proto.datajutsu.com](https://proto.datajutsu.com/?ref=datajutsu.com) runs this exact encode path, so paste a schema, hand it JSON that does not match, and watch which fields survive and which quietly disappear before the bytes come out.