You can use $request->get_json_params()
which will return an array of key => values.
With these conditions(possibly a few more):
- The client sending the request has
Content-Type: application/json
in the header - There is a raw body like
{"option":"siteColor","value":"ff0000"}
.
https://developer.wordpress.org/reference/classes/wp_rest_request/get_json_params/