Tool Kumar tool

JSON to Protobuf

Generate proto3 messages from a JSON example. Field types follow the protobuf JSON mapping, so protojson, JsonFormat or json_format reads the same document back, and json_name keeps keys that differ from the field names.

How to use this tool

  1. Paste a representative response, including records whose fields differ.
  2. Review the generated output and change the root name if needed.
  3. Copy or download the code, then check the types against your API contract.

Worked example

This output comes from the built-in converter. The two item prices infer a floating-point field; the null and string notes infer a nullable field.

Input

{
  "user-id": 42,
  "profile": {
    "city": "London",
    "created_at": "2026-10-14T09:00:00Z"
  },
  "items": [
    {
      "price": 12,
      "note": null
    },
    {
      "price": 12.5,
      "note": "gift"
    }
  ]
}

Output

syntax = "proto3";

package root;

import "google/protobuf/timestamp.proto";

message Root {
  int64 user_id = 1 [json_name = "user-id"];
  Profile profile = 2;
  repeated Item items = 3;
}

message Profile {
  string city = 1;
  google.protobuf.Timestamp created_at = 2 [json_name = "created_at"];
}

message Item {
  double price = 1;
  optional string note = 2;
}

Read existing JSON with protobuf

Keys such as firstName already match the JSON name protoc derives from first_name, so they need no option. Other keys, such as user-id, ID or 1abc, get json_name. When every key is snake_case, a note says to print JSON with proto field names instead.

Compile the file with protoc or buf and parse an API response with your language's JSON mapping. A service can then send binary protobuf to clients that ask for it while other callers keep receiving JSON.

protoc --python_out=. example.proto

from google.protobuf import json_format
import example_pb2

msg = json_format.Parse(body, example_pb2.Root())
wire = msg.SerializeToString()

Options and edge cases

  • Objects become messages, arrays become repeated fields, and objects keyed by data such as ids or dates become map<string, …> fields. Field numbers follow key order.
  • Scalars that are null or missing in some records are optional. Unknown, null-only and mixed values use google.protobuf.Value, and nested arrays use ListValue, because a repeated field cannot hold null or another list.
  • Integers are int64 and fractions are double. Protobuf JSON writes int64 values as strings; integers beyond the int64 range are marked because a double rounds them.
  • RFC 3339 date-times become google.protobuf.Timestamp, which prints in UTC. Dates, UUIDs and emails stay string; enums and validation rules need your API contract.

Private by default

Your document stays in this browser. Tool Kumar parses, converts and creates downloads on your device, with no account or upload step.

JSON to Protobuf questions

Does the generator write proto3?
Yes. The file starts with syntax = "proto3" and a package named after the root message, marks scalars that can be absent as optional and imports only the well-known types it uses, such as Timestamp and Value.
Will protobuf parse my original JSON?
The types follow the protobuf JSON mapping, so parsers such as protojson, JsonFormat and json_format read documents shaped like the sample. A key that protobuf cannot use as a JSON name, such as [0], is marked next to its field.
What if the JSON root is an array?
A protobuf message is always a JSON object, so the root message holds the array in a repeated items field. When the elements are objects, each one also gets its own message, which you can parse directly.
How are field numbers assigned?
From 1 in key order, skipping 19000 to 19999, which protobuf reserves. Once data is in use, keep each number and reserve the numbers of removed fields.

Related tools

JSON Schema generator, JSON to Go, JSON to TypeScript.