API Reference

protobuf.js

JavaScript Protocol Buffers implementation with runtime message classes, reflection, and JSON mapping.

Official Documentation ↗
CompatibilityThis documentation covers version v8.8.1. Check the official docs for the latest API surface.

Installation

npmnpm install protobufjs

Methods

protobufjs loads .proto schemas at runtime or uses generated static code to encode and decode messages.

Key Features

  • Dynamic reflection or static generated code
  • toObject and fromObject JSON mapping
  • verify for schema validation

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The following points are quoted verbatim from the official documentation (https://github.com/protobufjs/protobuf.js). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

What is the difference between static and dynamic code?
pbjs generates static modules with typed classes for build-time speed, while protobuf.load parses schemas at runtime, which is flexible but slower.
How do I map enums and bytes in JSON?
Pass options such as enums: String and bytes: String to toObject, or define your own conversion functions.
Does protobufjs validate messages?
Yes. Type.verify reports schema violations before encode, though Type.fromObject also coerces common mismatches.