JSON to Protocol Buffer (proto3) Generator — Free Online
Convert JSON to a Protocol Buffer proto3 message definition with correct field types and field numbers using AI. Free, no sign-up required.
JSON to Protocol Buffer (proto3) Generator — Free Online
About JSON to Protocol Buffer (proto3) Generator — Free Online
This tool converts a JSON object into a Protocol Buffer proto3 message definition, inferring field names, types, and nested message structures automatically. Developers use it to bootstrap .proto files from existing JSON APIs, reducing manual schema authoring when migrating services to gRPC or adding Protobuf serialization alongside a REST layer.
JSON to Protobuf Type Mapping
| JSON Type | JSON Example | Proto3 Type | Notes |
|---|---|---|---|
| string | "hello" | string | UTF-8 encoded text field |
| number (integer) | 42 | int64 | Use int32 if values fit within ±2 billion |
| number (float) | 3.14 | double | Use float to halve wire size when precision allows |
| boolean | true | bool | Maps directly to proto3 bool |
| null | null | optional <type> | Signals the field should be marked optional |
| object | { "key": ... } | message | Generates a nested message definition |
| array of strings | ["a","b"] | repeated string | repeated keyword replaces JSON arrays |
| array of objects | [{...},{...}] | repeated <MessageName> | Inner object becomes a separate message type |
| empty array | [] | repeated string | Falls back to repeated string; verify manually |
| integer that looks like ID | 123456789012 | int64 | Large integers default to int64 for safety |
Protobuf vs Alternative Serialization Formats
| Feature | Protobuf (proto3) | JSON | MessagePack | Avro |
|---|---|---|---|---|
| Schema required | Yes (.proto file) | No | No | Yes (.avsc file) |
| Binary encoding | Yes | No | Yes | Yes |
| Human readable | No | Yes | No | No |
| Typical size vs JSON | ~3–10x smaller | Baseline | ~1.5–2x smaller | ~2–4x smaller |
| Code generation | Yes (protoc) | N/A | N/A | Yes (avro-tools) |
| gRPC compatible | Yes (native) | Via transcoding | No | No |
| Schema evolution | Additive (field numbers) | Ad hoc | Ad hoc | Resolution rules |
| Language support | 20+ official | Universal | 30+ libs | JVM-centric, others exist |
| Repeated fields | repeated keyword | JSON array | Array type | array type |
| Null / optional | optional keyword | Native null | nil type | union with null |
Frequently Asked Questions
How do I convert JSON to a .proto file?
Paste your JSON object into a JSON-to-Protobuf converter and it will generate a proto3 message block with inferred field names and types. You can then save that output as a .proto file and compile it with protoc. Review generated int32/int64 and float/double choices before committing, since the tool picks conservative defaults.
What proto3 type should I use for a JSON number?
Proto3 has no single numeric type — you choose based on range and precision. Use int32 for whole numbers within ±2,147,483,647, int64 for larger integers or IDs, float for decimals where ~7 significant digits is enough, and double when you need ~15 significant digits. JSON numbers with a decimal point are mapped to double by default.
How are JSON arrays represented in Protobuf?
JSON arrays become repeated fields in proto3. For example, a JSON array of strings maps to repeated string, and an array of objects maps to repeated <MessageName> where the object's schema is extracted into its own message definition. There is no direct equivalent of a mixed-type JSON array — all elements must share the same proto type.
Can I convert nested JSON objects to Protobuf?
Yes. Each nested JSON object becomes a separate proto3 message, and the parent message holds a field of that message type. For example, { "address": { "city": "NYC" } } generates an Address message with a string city field, and the parent message declares Address address = N;. Deeply nested structures produce a chain of message definitions.
What is the difference between proto2 and proto3 for JSON mapping?
Proto3 is the recommended version for new projects and removes required fields, making all fields optional by default with zero-value defaults (0, "", false). Proto2 supported required and optional keywords explicitly and allowed custom default values. When converting from JSON — where missing keys are common — proto3 is a better fit because absent JSON fields simply receive the proto3 zero value rather than causing parse errors.
If jsondecode.com saved you time, share it with your team
Free forever. No ads. No sign-up. Help other developers find it.