If I insert an `Option<sqlx::types::Json<Struct>>` sqlx writes the text `null` in DB instead of mark that field as `NULL`

JSON has its own nullable type, null, so if you ask for JSON serialization of a nullable value, you will get the valid JSON string null. And you are asking for exactly that, since you are wrapping the whole person argument (which is Option<Person>) into Json.

I guess you should instead ask for NULL-or-JSON, i.e., Option<Json<Person>> instead of Json<Option<Person>>, which is person.map(Json).

2 Likes