jsontoolskit.org
JSON and JSON Schema utilities, in the browser
Say hi →

JSON to Protobuf

JSON sample → proto3 messages · updated 28 July 2026

Generate a .proto schema from a JSON sample. Field names become snake_case as the style guide requires, field numbers are assigned in order, arrays become repeated, and nested objects become their own messages.

Paste input to start.

How to generate a protobuf schema from JSON

  1. Paste a JSON sample — ideally an array of several records, so optional fields are detected.
  2. Set the Root type name. Nested objects are named after the key that holds them, singularised for arrays.
  3. Set a Package to namespace the generated code.
  4. Tick optional to get proto3 explicit presence, so you can tell "absent" from "zero".
  5. Tick json_name to keep the original JSON spelling in protobuf's JSON mapping.
  6. Copy the code, or download it as a file.

Field numbers are a contract

Numbers here are assigned 1, 2, 3… in key order, which is fine for a brand-new schema and wrong for an existing one. Field numbers, not names, are what protobuf writes on the wire. Once a message is deployed:

Numbers 1–15 use one byte, so give them to your most frequent fields.

Type mapping

Getting good types out of a sample

Type inference from a sample is only as good as the sample. Three habits make the output far more useful:

Privacy

Nothing is uploaded. Inference and code generation run in this tab. No server sees the payload you paste — which matters, because real API responses tend to contain real user data.

FAQ

Does proto3 have nullable fields?

Scalars have no natural null: an unset int64 reads as 0. The optional keyword (restored in protobuf 3.15) adds explicit presence tracking so you can distinguish unset from zero. Wrapper types such as google.protobuf.Int64Value are the older workaround.

Can it generate maps?

No. A JSON object with arbitrary keys is indistinguishable from a fixed-shape message in a sample. If your keys are dynamic, change the field to map<string, T> by hand.

How do I get an Avro schema instead?

Use JSON → Avro — same inference, different target. Avro is the usual choice for Kafka with a schema registry.