Protobuf Field Options Are Just Metadata (and Your json_name Is Not the Key You Get)
Every field in a .proto can carry an option in brackets after it, and two of them are worth knowing because a JavaScript parser stores both and behaves with them in two completely different ways. I fed [deprecated=true] and [json_name=...] into protobufjs 7.4.0 and measured what actually happened, because the spec says one thing and the parser does another. The first is pure metadata. The second changes the key you get in JSON, and the parser ignores the part of it that makes the spec true.
Start with deprecated. A field marked [deprecated=true] keeps the option on itself, visible in the serialized output, and that is the whole of it. The field encodes and decodes byte for byte like a field that was never marked. I wrote a field old with the flag and a fresh field next to it, encoded old=7 and fresh=hi, and got six bytes. A copy of the schema with the flag removed decodes those same six bytes to the same two values. There is no marker on the wire, no slower path, no warning. The flag is for the code generator and the person reading the file, not the bytes. A deprecated enum member works the same way, parked in a separate valuesOptions bag on the enum, and the value still encodes to its plain varint. The tool does not read the flag anywhere, so nothing on any tab reacts to it.
Now json_name, and where it opens up. The official JSON mapping says this option overrides the field key in JSON, so user_name with [json_name="customKey"] should come out as customKey. The parser stores exactly that, options.json_name is customKey and it round trips clean. But the field's own name is still the camel-cased user_name, and the property that is supposed to carry the custom name is undefined. So when I serialize, the key I get is the camel-cased one, userName, not the customKey I wrote. The override is sitting there in the options bag, readable if you dig, and the encoder never looks at it.
The input side is where it bites. I can feed the camel-cased key, userName, and it is kept. I can feed the original snake key, user_name, and it is silently dropped, the field comes back empty. And I can feed the custom name I actually set, customKey, and it is silently dropped too. Three spellings of the same field, one that works, two that vanish with no error. So the field you named in the option is not the name you hand the tool. You hand it the camel-cased one, and the option you wrote to control the key does the controlling for nobody.
Turning on keepCase does not rescue it. The field keeps its snake_case name, but the custom-name property is still undefined and the override is still ignored. The only difference is which default you fall back to. If you want the raw snake key in and out you take keepCase, and you give up the camel default, but the json_name you typed is still just sitting in the options, visible if you look for it, unused if you don't.
So the two options sit at opposite ends. deprecated is inert metadata, safe to add or remove late, it changes nothing a wire reader or a JSON reader sees, and that is the point, it is a label. json_name is the one that changes the JSON, and the parser stores it and does not apply it, so a file that is clean against the spec produces a different key than the tool hands you, and the key you hand the tool is not the one you named. The four default JSON rules are in the JSON mapping post, and the deprecate-then-reserve habit is in the reserved-fields post. Paste the file into proto.datajutsu.com and both options parse on every tab; json_name is the one to check when your JSON keys stop matching the schema.