> ## 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 Text Format Is a Third Format (and It Is Not the JSON You Assume)
- URL: https://datajutsu.com/protobuf-text-format-is-not-json/
- Published: 2026-11-02T19:28:25.000Z
- Updated: 2026-11-02T19:28:25.000Z
- Author: Data Jutsu

Most people who touch protobuf know two formats. There is the compact binary, the tags and varints that actually ride on the wire, and there is the JSON mapping, the document the spec says a JSON producer must emit. There is a third, and it is the one that surprises people, the human readable text format that protoc --encode prints and --decode reads. It is not the wire, and it is not JSON. It has its own escape style, its own strictness, its own ordering, and if you treat it like JSON, which is what you do the first time you see it, you will be stopped by a parser that is stricter than the bytes you were trying to write.

The first thing that gives it away is how it writes a bytes field and a 64 bit integer, and it does both differently from the JSON mapping. I made a bytes field with the four bytes 0x61, 0x01, 0xff, 0x7f and read it back through protoc --decode. It came out as blob: "a\\001\\377\\177", every non printable byte rendered as a three digit octal C escape. The JSON mapping of that same field is the base64 string "YQH/fw==". Different alphabet, different reader, same field. A 64 bit integer goes the other way. The text format prints the raw number, id: -1 and id: 9223372036854775807, while the JSON mapping wraps it in quotes, "-1", because a plain JavaScript number would eat the low bits. So the text format writes out the bare integers that the JSON mapping strings, and strings the bytes that the JSON format escapes. The two formats make opposite choices on the same two field types, and both are right for their reader. The integer choice is the whole subject of the [negative int post](https://datajutsu.com/protobuf-negative-int-json/?ref=datajutsu.com) and the bytes one is covered in the [bytes versus string post](https://datajutsu.com/protobuf-bytes-vs-string/?ref=datajutsu.com).

The part that actually bites is that the text format is a gatekeeper while the wire is a pass through. I put the same non repeated field in a message twice. The wire carries both occurrences and the decoder quietly keeps the last one, no complaint, which is the whole duplicate field story. But the text format refuses to read it. Parse a stream that names the field twice and it stops with the message that the type should not have multiple name fields, and protoc --encode refuses to write it in the first place, saying the non repeated field is specified multiple times. A oneof behaves the same way. The wire, being nothing but field numbers, will happily carry whichever member was written last, but the text format reads email and then phone in the same message and halts, because phone is specified along with email, another member of the same oneof. The bytes are lenient by design, they do not know what a field is. The text format is strict by design, it knows exactly what the schema says and it will not let a human write a message the schema cannot hold. They are doing different jobs, and confusing them is where the debug session goes sideways. The duplicate case, with the decoder keeping the last value, is in the [duplicate fields post](https://datajutsu.com/protobuf-duplicate-fields-last-wins/?ref=datajutsu.com).

The names it accepts are a quieter trap. It matches the field names exactly as they appear in the .proto, the snake case ones, so first\_name parses. It does not accept the json\_name, the camelCase alias: paste firstName in and it tells you the message has no field named firstName, even though the JSON mapping reads firstName without a thought. A field that carries a \[json\_name\] option has two names in JSON and one in text, and the only one the text format will take is the snake case one. Enum members are matched by name too, and the match is exact on case: GREEN parses, green does not, and Green does not. An unknown enum value is a different matter and the text format is fine with it; color: 99 parses, and it round trips as the bare number, so a member your schema does not know about survives a write and read in text just as it does on the wire. All of this sits on top of the mapping rules in the [JSON mapping post](https://datajutsu.com/protobuf-json-mapping/?ref=datajutsu.com), which is where the json\_name behavior comes from.

Three more things, all of them small and all of them easy to trip on. The output is ordered by field number, not by the order you wrote the lines, so a file that lists name before id still comes back as id, then name, then blob, because that is the field number order. Comment lines start with a hash and are dropped, and there is no comment slot in the message, so the notes in your .proto never ride along with the data. And the format is not JSON. It needs no braces, it allows single quotes, a field is just name: value, and if you hand it to a JSON parser it fails on the first character. People reach for it precisely because it looks like a looser JSON, and that looseness is where it breaks them.

The [tool at proto.datajutsu.com](https://proto.datajutsu.com/?ref=datajutsu.com) works the wire bytes and the JSON mapping, the two formats machines actually send, and it deliberately does not take the text format. That is why a round trip through the tool is bytes to bytes, not text to JSON, and why a message you hand built with protoc --encode has to be --decoded back to the wire before the tool will read it. The one place the text format is genuinely useful is as a human readable diff and a debug window: read a message as text, change one field by hand, and --encode it back, and you have a minimal patch without touching the schema or regenerating any code. It is the format you use when you are talking to another person, not when you are talking to the wire. The wire format itself, the thing the text format is a loose transcription of, is in the [wire format post](https://datajutsu.com/how-protobuf-wire-format-works/?ref=datajutsu.com).