I am always looking for answers.
Unfortunately, some web frameworks including actix handle JSON error before we can do any validation. I keep searching for using various keywords. One of them is "actix-web validate JSON" which leads me to many validator crates. But I get insight from this blog saying that:
Extractors are helpers that implement the FromRequest trait. In other words, they construct any object from a request and perform validation along the way. A handful of useful extractors are shipped with Actix web, such as JSON which uses serde_json to deserialize a JSON request body
So, I search for "actix Extractor" and bring me Extractor Doc and custom handling of extractor errors
So this snippet is taken from this boilerplate solves my current problem.
App::new()
.configure(health::init)
.configure(students::init)
+ .app_data(web::JsonConfig::default().error_handler(|err, _req| {
+ error::InternalError::from_response(
+ "",
+ HttpResponse::BadRequest()
+ .content_type("application/json")
+ .body(format!(r#"{{"error":"{}"}}"#, err)),
+ )
+ .into()
+ }))

