prost-wkt

JSON serialization and serde support for Protobuf Well-Known Types in Rust

Library
Cargo
v0.7.1
96stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
52/100Fair
Development Activity52
Maintenance28
Community48
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
70/100Good
Architecture78
Code Quality72
Innovation70
Learning Curve60

prost-wkt is a helper crate for the prost Protocol Buffers implementation that fills the gaps in prost-types’ handling of Well-Known Types. It adds proper JSON serialization and deserialization for the Any type, packing and unpacking of arbitrary messages, and serde support across Timestamp, Duration, Value, and other WKTs.

The crate integrates at build time through prost-build, deriving Serialize and Deserialize on generated structs and wiring up a MessageSerde trait so that Any payloads round-trip correctly through JSON exactly as the protobuf JSON mapping specification requires. It also provides ergonomic conversions between chrono date/time types and protobuf Timestamp, and between common Rust values and protobuf Value.

What You Get

  • Helper methods for packing and unpacking messages to and from the protobuf Any type
  • Spec-compliant JSON serialization and deserialization of Any via a MessageSerde trait
  • serde Serialize and Deserialize support for Timestamp, Duration, Value, and other Well-Known Types
  • Conversions between chrono date/time types and protobuf Timestamp
  • Optional schemars integration for generating JSON Schema from the WKT types

Common Use Cases

  • Exposing gRPC/protobuf messages that contain Any fields over a JSON REST or web API
  • Logging or persisting protobuf messages as human-readable JSON
  • Converting between chrono timestamps and protobuf Timestamp in Rust services
  • Generating JSON Schema documents from protobuf-defined types via schemars

Under The Hood

Architecture - prost-wkt is a Cargo workspace of three published crates: prost-wkt (in wkt/) defines the core MessageSerde trait using typetag and inventory for type-tagged serialization and downcasting of Any payloads; prost-wkt-types (in wkt-types/) provides the concrete Well-Known Type implementations and serde impls generated from the bundled protos; and prost-wkt-build (in wkt-build/) injects the required derives and extern paths into prost-build’s code generation via an add_serde helper invoked from a consumer’s build.rs.

Tech Stack - Pure Rust (edition 2021, MSRV 1.82) built on prost 0.14 and prost-types, with serde/serde_json for serialization, chrono for timestamp conversions, and typetag plus inventory to register and resolve message types at runtime. schemars is an optional dependency behind a feature flag.

Code Quality - The MessageSerde trait mirrors the standard library’s dyn Any downcasting implementation closely, with documented safety invariants around the unchecked downcasts. The wkt-types crate carries an integration test suite exercising round-trip JSON serialization. Code is idiomatic and well commented.

API Design - Day-to-day use is ergonomic: Any::try_pack, try_unpack, and downcast_ref cover the common flow, and chrono values convert with plain into(). The main friction is one-time build.rs configuration, which the README documents thoroughly, including the known oneof submodule serde-import caveat.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search