Skip to content

ProtoToJson is a tool to decode and view binary protobuf messages as readable JSON.

License

Notifications You must be signed in to change notification settings

Zabuzard/ProtoToJson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ProtoToJson

codefactor maven-central javadoc Java license

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.

Requirements

  • Requires at least Java 11

Download

Maven:

<dependency>
   <groupId>io.github.zabuzard.prototojson</groupId>
   <artifactId>prototojson</artifactId>
   <version>1.1</version>
</dependency>

Jar downloads are available from the release section.

Documentation

Descriptor cache

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.

Developer API

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"));

Desktop application

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.

Select file dialog

The tool then decodes the message into JSON, provided a corresponding descriptor was found, and displays the result in a text editor window.

Decoded message