Loading JSON to Protobuf Converter...
Please wait a moment

How to Convert JSON to Protobuf - Step by Step Guide

Step 1

Input Your JSON Data

Start by entering your JSON data that you want a protobuf message for. An object works best; a top-level list or a single value is wrapped in a message for you:

•
Paste JSON data: Copy JSON from your REST APIs, databases, or web applications
•
Upload JSON files: Pick a .json or .txt file from your computer
•
Use sample data: Click Sample to load a small user record and see all three outputs

Example: JSON Input

Here's a typical JSON structure ready for protobuf conversion:

{
  "id": 456,
  "name": "Emma Thompson",
  "email": "[email protected]",
  "roles": [
    "manager",
    "architect"
  ],
  "active": true,
  "profile": {
    "department": "Product",
    "experience_years": 8,
    "skills": [
      "Leadership",
      "Strategy",
      "Design"
    ]
  }
}
Step 2

Check the Generated .proto Schema

The schema shows up a moment after you stop typing. It is plain proto3, checked with a real .proto parser before you see it, and it follows a few simple rules:

•
Types from the real digits: int32 when a value fits, int64 for long IDs like 8901240544102066246, double for anything with a decimal point
•
Every list item counts: keys from all records are merged, so a field that only appears in one of them still gets a number
•
Objects become messages: profile turns into a Profile message, a list of objects into a repeated message field
•
Names you can keep using: fields are snake_case, and json_name is added whenever proto3 would otherwise write the key differently in JSON

Example: .proto Schema Output

The JSON from Step 1 with the Message name set to User. Note that experience_years keeps its key through json_name, while roles needs nothing extra:

syntax = "proto3";

message User {
  int32 id = 1;
  string name = 2;
  string email = 3;
  repeated string roles = 4;
  bool active = 5;
  Profile profile = 6;
}

message Profile {
  string department = 1;
  int32 experience_years = 2 [json_name = "experience_years"];
  repeated string skills = 3;
}
Step 3

Pick an Output and Download It

•
.proto schema: Download saves it as root.proto (named after your message)
•
Binary (Base64): the wire bytes of your data, encoded with that schema and decoded back as a check. Copy gives you the Base64, Download .pb saves the raw bytes as data.pb, and the .proto button grabs the matching schema
•
Text format: the readable form, saved as data.txtpb, with the same field names and numbers as the schema and numbers written exactly as you typed them

Example: Checking the Binary with protoc

The Step 1 JSON is 206 bytes compacted and 101 bytes as protobuf. protoc can turn the bytes back into text with the downloaded schema:

protoc --decode=User user.proto < data.pb

What is JSON to Protobuf Conversion?

Protocol Buffers store data as numbered fields described by a .proto schema. JSON carries names but no numbers or types, so this page works the schema out from your data first: it numbers the fields in the order your keys appear, picks the narrowest type that holds every value it saw, and then encodes the data with that schema using protobufjs.

It is a quick way to get a first draft of a schema for an existing JSON API, to make binary test fixtures, or to see how much smaller a payload gets on the wire. A guess from sample data is still a guess, so look the schema over before you ship it. To go the other way, Protobuf to Table reads text format, .proto files and binary messages and shows them as a table.

Frequently Asked Questions

What do I get out of this converter?

Three things, picked from the Output menu. A proto3 .proto schema inferred from your data, the same data encoded as real binary protobuf (shown as Base64, downloaded as a raw data.pb file), and protobuf text format (.txtpb) using the schema's field names. All three come from one schema, so the field numbers and names always line up.

How are the field types chosen?

From the numbers as you typed them, not from a rounded JavaScript copy. Whole numbers that fit 32 bits become int32, bigger ones int64, and positive values past the int64 range uint64. Anything with a decimal point or an exponent is a double, and a field that holds both kinds becomes double too. Text is string and true/false is bool. A quoted value like "00501" stays a string, because that is what it is in the JSON.

Why is my long ID an int64 and not a string?

Because it is a number in your JSON. An ID like 8901240544102066246 fits in an int64 exactly, so the schema says int64 and the binary carries every digit. Most JSON tools quietly round it to 8901240544102066000 first; this one reads the digits straight from your text. Only a whole number outside the 64-bit range falls back to a string field, and a note says so.

What happens with lists, nested objects and nulls?

A nested object becomes its own message, a list of objects becomes a repeated message field, and a list of plain values becomes a repeated scalar. Types are merged across every item of a list, so a key that only shows up in the third record still gets a field. Proto3 has no null: a null field is simply left unset, and a null inside a list is dropped with a note. A field that is null everywhere is written as string, since there is nothing to infer from.

What does json_name do in the schema?

Protobuf field names are conventionally snake_case, so firstName is written as first_name. Proto3 already maps first_name back to firstName when it reads or writes JSON, so no option is needed there. When a key would come back differently, for example user_id, "first name" or a key that starts with a digit, the field gets [json_name = "..."] with your original key, so JSON produced from the message looks like the JSON you started with.

What can protobuf not express, and what does the tool do then?

A few JSON shapes have no direct protobuf form. Lists inside lists are wrapped: each inner list becomes a small message with a repeated values field. A field that mixes kinds, say numbers and strings, becomes a string field holding each value's JSON text. A top-level list is wrapped in a message with a repeated items field, and a single top-level value in a message with one field. Every one of these changes is listed in a note above the output.

How do I use the files in my project?

Save the .proto and compile it with protoc for your language, for example protoc --python_out=. root.proto, or load it at runtime with protobufjs. data.pb is ready to parse with the generated class, and data.txtpb starts with proto-file and proto-message comments so editors and protoc know which message it holds. Treat the schema as a starting point: rename messages, add enums and reserve old field numbers as your API grows.

Is my JSON uploaded anywhere?

No. The schema, the binary and the text format are all built in your browser with protobufjs, and the bytes are decoded again and compared with your JSON before anything is shown. Nothing you paste or upload is sent to our server.