Registry / devops / protobuf-jsonschema

protobuf-jsonschema

JSON →
library1.1.1jsnpmunverified

A Node.js library and CLI tool that compiles Protocol Buffers IDL (proto files) into JSON Schema definitions. As of version 1.1.1, it supports proto3 syntax and can output JSON or YAML, making it useful for generating OpenAPI/Swagger specs. It can compile all messages from a file or target a specific message with its dependencies. The project appears to be in maintenance mode with no recent updates.

npm install protobuf-jsonschema
INSTALL
IMPORT
SIG · PROTOBUF-JSONSCHEM
P
protobuf-jsonschema
devopsjavascriptv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

compile
const compile = require('protobuf-jsonschema');
import compile from 'protobuf-jsonschema';
Package uses CommonJS; ESM import will fail.
compile
const { default: compile } = await import('protobuf-jsonschema');
For ESM projects, use dynamic import with default export.
compile
import * as proto2json from 'protobuf-jsonschema'; const compile = proto2json.default;
Alternative ESM workaround.

Compiles a Protocol Buffers IDL file into JSON Schema using the library in Node.js.

// Create a test.proto file // syntax = "proto3"; // message Person { // string name = 1; // int32 age = 2; // } const compile = require('protobuf-jsonschema'); const path = require('path'); // Compile all messages const allSchemas = compile(path.join(__dirname, 'test.proto')); console.log(JSON.stringify(allSchemas, null, 2)); // Compile a specific message const personSchema = compile(path.join(__dirname, 'test.proto'), 'Person'); console.log(JSON.stringify(personSchema, null, 2));
Debug
Known issues
gotchaThe package does not support proto2 syntax; only proto3 is supported.
fix
Ensure all .proto files use syntax = "proto3";
affects: >=1.0.0
gotchaFile paths passed to the compile function must be absolute; relative paths may cause errors.
fix
Use path.resolve() to convert relative paths to absolute before passing.
affects: >=1.0.0
gotchaThe library does not handle imports inside .proto files; you may get incomplete schemas.
fix
Manually resolve imports or concatenate all proto files into one before compiling.
affects: >=1.0.0
deprecatedThe CLI global install method is deprecated; use npx instead.
fix
Run command with npx: npx protobuf-jsonschema --help
affects: >=1.0.0
Errors
Common errors & fixes
Error: ENOENT: no such file or directory, open 'models.proto'
Relative path resolution issue; the library expects an absolute path.
fix
Use path.resolve(__dirname, 'models.proto') to provide absolute path.
SyntaxError: Unexpected token in proto file
Proto file uses syntax other than proto3 (e.g., proto2).
fix
Add 'syntax = "proto3";' at the top of your .proto file.
TypeError: compile is not a function
Using ES6 import with default import which doesn't work with CommonJS modules.
fix
Use require('protobuf-jsonschema') instead of import.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
protobuf-jsonschema — npm install protobuf-jsonschema · libregistry