Skip to content

Menu

JSON to Protobuf

Convert JSON to Protocol Buffer definitions

Runs entirely in your browserConvertersFree, no sign-up
Loading tool

01What is JSON to Protobuf?

Moving a JSON service to gRPC or Kafka means writing .proto files, and typing them from a sample payload is tedious work. This tool reads a JSON object or array and drafts a proto3 schema you can refine. The output starts with syntax = "proto3"; and, if you set one, a package line. Package parts are cleaned so each is a valid identifier. Then you get one message per object, with nested messages listed before the root message. Field names follow the Protocol Buffers style guide, which asks for lower_snake_case. So isActive becomes is_active, full-name becomes full_name and 2fa becomes field_2fa. Whenever a name changes, a trailing comment records the original JSON key. If two keys map to the same name, such as userId and user_id, the second gets a suffix like user_id_2. Field numbers start at 1 and follow the order keys appear in your sample. Types come from the values. In the .proto output, strings become string fields, booleans bool and decimals double. Integers map to int32, or int64 when a value falls outside the 32-bit range. Nested objects become their own message, named after the key in PascalCase. Two objects with identical fields share one message, so {"a":{"x":1},"b":{"x":2}} produces a single message A used by both fields. Arrays become repeated fields. For object arrays, the items are merged into one message holding every key seen. That is safe because proto3 fields are optional on the wire. Number arrays become repeated double if any value has decimals, or int64 if any value is too big for int32. Empty, mixed and nested arrays fall back to repeated string with a comment explaining why. A null value becomes optional string with a // was null comment. For example, paste {"items":[{"id":1},{"id":2,"qty":3}]}. You get message Items with int32 id = 1 and int32 qty = 2, plus message Root with repeated Items items = 1. A top-level array is wrapped in a Root message with a repeated items field. Bare strings, numbers and null are rejected with "Input must be a JSON object or array". Treat the result as a first draft. Timestamps stay as string, and a whole number in the sample becomes int32 even if the field can hold decimals. Enums, maps, oneofs and well-known types are never generated. The conversion runs in the page itself, so your sample payload never reaches a server.

Backend engineers moving JSON services to gRPC and data teams defining event schemas from real payloads. The tool runs entirely in your browser, so your data never leaves your device.

02How to use JSON to Protobuf

  1. Optionally type a Package name, such as acme.users.v1.
  2. Set the root Message name. It defaults to Root.
  3. Paste a JSON object or array into JSON Input, or pick one of the examples.
  4. Review the Protobuf Output, paying attention to fields that carry comments.
  5. Click Copy, save it as a .proto file and compile it with protoc or buf.

03Worked examples

Input: {"user_id":7,"full-name":"Ann","price":9.99,"tags":["a","b"],"address":{"zip_code":"0150"},"meta":null} with Package demo.v1
Result: syntax = "proto3"; package demo.v1; message Address { string zip_code = 1; } message Root { int32 user_id = 1; string full_name = 2; // JSON key "full-name" double price = 3; repeated string tags = 4; Address address = 5; optional string meta = 6; // was null }
A comment records the original key when the name changed. null becomes optional string.
Input: {"items":[{"id":1},{"id":2,"qty":3}],"empty":[]}
Result: message Items { int32 id = 1; int32 qty = 2; } message Root { repeated Items items = 1; repeated string empty = 2; // empty array, type unknown }
Fields from every item are merged into one message. The syntax line is trimmed.
Input: {"big":9007199254740993,"mixed":[1,"a"],"ints":[1,2.5]}
Result: message Root { int64 big = 1; repeated string mixed = 2; // mixed types, using string repeated double ints = 3; }
Values beyond 32-bit range become int64. Mixed arrays fall back to repeated string. Syntax line trimmed.
Input: {"userId":1,"user_id":2,"2fa":true,"isActive":false}
Result: message Root { int32 user_id = 1; // JSON key "userId" int32 user_id_2 = 2; // JSON key "user_id" bool field_2fa = 3; // JSON key "2fa" bool is_active = 4; // JSON key "isActive" }
Colliding names get a suffix, and a leading digit gets a field_ prefix. Syntax line trimmed.
Input: [{"id":1},{"id":2}]
Result: message Items { int32 id = 1; } message Root { repeated Items items = 1; }
A top-level array is wrapped in Root as a repeated items field. Syntax line trimmed.
Input: {"a":{"x":1},"b":{"x":2},"grid":[[1,2]]}
Result: message A { int32 x = 1; } message Root { A a = 1; A b = 2; repeated string grid = 3; // nested array, consider restructuring }
Objects with identical fields share one message. Nested arrays are flagged because proto3 has no repeated repeated. Syntax line trimmed.

04Common use cases

  • Bootstrapping .proto files when moving a JSON REST service to gRPC
  • Defining Kafka or Pub/Sub message schemas from sample event payloads
  • Producing a starting schema that buf lint and code review can then tighten up
  • Spotting key collisions like userId and user_id before they become wire-format problems
  • Comparing a familiar JSON payload with its proto3 shape while learning Protocol Buffers
  • Drafting messages for a mobile API migration to see which fields need enums or Timestamps

05Tips

  • Once a schema is in use, never renumber fields. Add new fields with fresh numbers and mark removed ones as reserved.
  • Field numbers 1 to 15 take one byte on the wire, so move frequently set fields into that range before you ship.
  • Swap date strings for google.protobuf.Timestamp. The tool only sees text, so it always picks string for them.
  • Every comment in the output flags a guess: a renamed key, a null, an empty or mixed array. Review those lines first.
  • If the JSON keys must stay camelCase on the wire through JSON mapping, protoc already converts snake_case fields to lowerCamelCase JSON names.

06Related concepts

Protocol Buffers, proto3, gRPC, Schema evolution, Field numbers.

Frequently Asked Questions

What is JSON to Protobuf?

JSON to Protobuf is a free, browser-based developer tool on AIDToolStack. Convert JSON to Protocol Buffer definitions It requires no installation or sign-up and works entirely in your browser.

Is JSON to Protobuf free to use?

Yes. No sign-up, no fees and no usage cap.

Does JSON to Protobuf store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe