Back to Questions
How do I parse a JSON request body in Actix Web?
Asked 3/10/2026Viewed 1530 timesStatus: OPEN
Display Only / Sanitized
I'm trying to receive a JSON payload in my POST request, but I keep getting an error about the Deserializer. How do I properly use `web::Json`?
jsonextractorsrouting
Asked byRustacean42
1 Answers
Accepted
Display Only / Sanitized
You need to add `serde` and `serde_json` to your `Cargo.toml`. Then, define a struct with `#[derive(Deserialize)]`. ```rust use actix_web::{web, App, HttpServer, Result}; use serde::Deserialize; #[derive(Deserialize)] struct Info { username: String, } async fn index(info: web::Json<Info>) -> Result<String> { Ok(format!("Welcome {}!", info.username)) } ``` The `web::Json` extractor will automatically deserialize the body.
Answered on 3/10/2026
Actix Web Maintainer Official