From JSON to Protobuf: Inferring a Schema From a Sample
August 10, 2026 · DevTools
Protocol Buffers give you a strongly typed contract for your data, but writing a .proto file by hand for an existing JSON API is tedious. The faster path is to infer the schema from a representative JSON sample, then tighten it.
The rules are straightforward. A JSON string becomes string, an integer becomes int32, a decimal becomes double, and a boolean becomes bool. A nested object becomes a nested message, and an array becomes a repeated field typed from its first element. Field names are snake_cased and numbered in source order, and message names are PascalCased, matching the proto3 style guide. A single record like {"id": 1, "name": "Ada", "tags": ["x"]} yields fields int32 id, string name, and repeated string tags.
Two cases always need a human look. Very large identifiers that fit in JSON numbers can overflow int32, so switch them to int64. And an empty array tells you nothing about its element type, so the inferred repeated string is only a placeholder. Supply a richer sample, or set the type yourself, and the schema is ready to ship.