serde
Serialization framework for Rust
A Rust library that converts data between Rust types and external formats like JSON, TOML, or YAML, just add a derive annotation to your struct and Serde generates all the conversion code automatically.
Serde is a library for Rust that handles converting data between Rust types and external formats like JSON, TOML, or YAML. The name is a portmanteau of "serialization" and "deserialization," which describe the two directions of that conversion: taking a Rust value and encoding it as text or bytes (serialization), and taking text or bytes and turning them back into a Rust value (deserialization).
The library's main design goal is to let you work with your own data types directly, rather than converting everything through an intermediate generic structure. You annotate a struct or enum with a derive attribute, and Serde generates the code to serialize and deserialize it automatically. This means you define a Point struct with x and y fields, add the derive annotation, and Serde handles turning that struct into JSON and back without any hand-written conversion code.
Each data format is packaged separately. The core Serde library defines the traits and interfaces, while format-specific crates like serde_json, serde_yaml, and others implement them. This means you can switch from one format to another by changing which crate you use, while keeping the same data type definitions in your code.
Serde is described as one of the most widely used Rust libraries. It works without the Rust standard library (no-std environments), making it suitable for embedded systems and similar constrained contexts. The library requires Rust 1.56 or later for the core crate, and Rust 1.71 or later if you use the derive feature for automatic code generation.
The README is brief and points to the project's documentation site for more detail, including a list of all supported data formats, usage examples, and the full API reference. The library is licensed under either the Apache 2.0 or MIT license, at the user's choice.
Where it fits
- Parse a JSON API response directly into a typed Rust struct with a single derive annotation and no hand-written code.
- Read a TOML or YAML config file into a Rust struct without writing any manual parsing logic.
- Switch your data format from JSON to another format by swapping one crate, keeping the same struct definitions.
- Use Serde in an embedded Rust project without the standard library by enabling the no-std feature.