JSON to Protobuf Converter
CV-77Paste a JSON sample and press Convert to get a proto3 schema of messages. It infers the types from every item in your sample, and it runs in your browser.
Runs in your browser. Nothing is uploaded.
JSON
Protocol Buffers
How to use it
- Paste a JSON sample into the input box, or open a .json file. Use a sample that shows every key you expect.
- Choose whether null or missing keys get optional, and whether date-time strings use google.protobuf.Timestamp.
- Press Convert, then copy the result or download it as a .proto file.
- Save it as a .proto file and compile it with protoc for your language.
How the messages are built
Each object becomes a proto3 message, with field numbers counted from 1 in the order the keys appear. Field names are snake_case, and a json_name option keeps the original key when the default JSON name would differ. Types are int32, int64 beyond the 32-bit range, double, bool and string, and arrays become repeated fields. A list inside a list gets a small wrapper message, because Protocol Buffers cannot repeat a repeated field.
How the JSON is read
The JSON is read with a parser that keeps number text exactly, so a big integer is not rounded before its type is chosen. Every object in the sample is merged by key, so a key missing from some objects is marked optional and a null in some items marks the key nullable. If the document is a top-level array, its items are merged into one type named after the root name with Item added. Keys that are not valid Protobuf names, such as first-name, are renamed, and the original key is kept in a json_name option.
What a sample cannot tell it
The result only reflects the sample you paste: a key that never appears has no member, and a number that is always whole in the sample is typed as whole even if other data holds decimals. Field numbers follow the key order of this one sample; once a message is in use, never renumber its fields. Check the result against the API documentation before you rely on it.
Questions people ask
How do I convert JSON to a Protocol Buffers schema?
Paste the JSON into the input box, choose your options and press Convert to get the messages. Save it as a .proto file and compile it with protoc for your language. The conversion happens in your browser.
How are the protobuf field numbers chosen?
Fields are numbered from 1 in the order the keys appear in your sample. That is fine for a new schema, but once a message is in use never renumber its fields, because the numbers identify fields on the wire.
How does an array become a Protocol Buffers field?
An array becomes a repeated field. A list inside a list cannot be repeated twice, so the tool writes a small wrapper message with a values field. A top-level array has no message form, so the output only adds a comment saying it is a list.
What does the optional setting do in the proto3 output?
In proto3 a scalar field marked optional can tell a missing value from zero. With the setting on, scalar keys that are null or missing in some items get optional. Message fields already track presence, and repeated fields cannot be optional.
What happens when my JSON starts with an array?
The tool reads every item and merges them into one type, so a key present in only some items becomes optional. The output names that type after the root name with Item added, and a comment at the top says the document is a list. The Protobuf messages are written from the parsed sample.
How are very large numbers in the JSON sample handled?
Number text is kept exactly while types are picked, so a value like 12345678901 gets a 64-bit type where the language has one, and an integer beyond 64 bits is flagged rather than silently rounded. JSON Schema only records integer or number. The Protobuf messages are written from the parsed sample.
About this tool
The classes are inferred from the JSON you paste, so they only know what the sample shows. Every object becomes a proto3 message, numbered from 1 in the order the keys appear. Field names are snake_case, and a json_name option keeps the original key when the default JSON name would differ. Types are int32, int64 (beyond 32 bits), double (decimals, and integers beyond int64, with a comment), bool and string; arrays become repeated fields, and a list inside a list gets a small wrapper message because Protocol Buffers cannot repeat a repeated field. A key that is null or missing in some items becomes optional when it is a scalar, and mixed types and always-null keys become google.protobuf.Value, which needs the struct.proto import the output adds. The optional Timestamp choice maps ISO date-time strings. It writes no package, service or enum. Everything runs in your browser; nothing is uploaded.