ProtoToJson is a tool to decode and view binary protobuf messages as readable JSON.
It is able to decode any message, provided a descriptor of its protobuf schema was put into its cache.
The tool offers an API as well as a small desktop application.
- Requires at least Java 11
Maven:
<dependency>
<groupId>io.github.zabuzard.prototojson</groupId>
<artifactId>prototojson</artifactId>
<version>1.1</version>
</dependency>
Jar downloads are available from the release section.
- API Javadoc or alternatively from the release section
In order to decode protobuf messages, the tool uses protobuf descriptor files which have to be provided in its cache. The cache for the desktop application is located at
%LOCALAPPDATA%\ProtoToJson\descriptorCache
Such descriptor files foo.desc
can be obtained by executing
protoc --descriptor_set_out foo.desc foo.proto
on the protobuf schema foo.proto
. However, this requires
the protobuf compiler protoc
to be installed.
The module exports the package
de.zabuza.prototojson.api;
which contains an API ProtoToJson.java
that can be used as Java library as well.
An example usage could be:
DescriptorCache cache = DescriptorCache.fromDirectory(Path.of("descriptorCache"));
ProtoToJson protoToJson = ProtoToJson.fromCache(cache);
String json = protoToJson.toJson(Path.of("someProtoMessage.message"));
Upon launch, the application reads its descriptor cache located at
%LOCALAPPDATA%\ProtoToJson\descriptorCache
If it was started with an argument, the first argument will be interpreted as path to a binary protobuf message file to decode. Otherwise, the user is prompted to select one.
The tool then decodes the message into JSON, provided a corresponding descriptor was found, and displays the result in a text editor window.