serde_json is the JSON implementation for the Serde Rust framework. It maps between JSON text and Rust types, offers a dynamic Value type, and includes a json! macro for building values.
Overview
serde_json integrates with Serde to serialize and deserialize Rust data structures to JSON efficiently. You can parse strings or byte slices into typed structs using from_str, or work with an untyped Value enum when the schema is unknown.
Value indexing lets you navigate maps and arrays without defining structs first, though strongly typed derives reduce runtime errors in larger codebases. A json! macro builds JSON literals with natural syntax, and to_string prints values as JSON text.
Readers and writers support streaming IO for files and network streams. The crate is widely used anywhere Rust programs exchange JSON with HTTP APIs, config files, or CLI tools.
Documentation on crates.io and docs.rs covers error handling, number precision, and compatibility with Serde custom types.
Key features
- Serialize and deserialize Rust types
- Dynamic Value tree for untyped JSON
- json! macro for literal construction
- from_str, from_slice, and from_reader parsers
- Efficient string and binary JSON IO
- Works with Serde derive macros
Use cases
- Parse HTTP JSON into Rust structs
- Manipulate JSON without fixed schemas
- Emit configuration files from Rust binaries