How can we convert .proto file and JSON descriptors?

Viewed 930
1 Answers

Robocco, you can convert your proto file definition into protobufjs.Root and then use method toJSON() to get JSON descriptor.

Here is a related example from documentation.

const protobufjs = require("protobufjs")

const root = protobufjs.loadSync('test.proto');
// Alternative way without loading proto string from file 
// const root = protobufjs.parse('syntax = "proto3"; ...').root;​
console.log(JSON.stringify(root.toJSON(), null, 4));
Related