json.response
Mutate the entire JSON response object.
Return JSON_MUTATE_MODIFIED after calling write_json_output, or JSON_MUTATE_UNCHANGED to keep the prior value.
Use cases
- Add plugin-specific metadata to status responses
- Rewrite fields for panel compatibility
Example
Registration and handler
Register
hook_json!(host, JsonMutateTarget::ResponseBody, "/api/system", on_body);Handler
extern "C" fn on_body(ctx: *const JsonMutateContext) -> i32 {
let ctx = unsafe { &*ctx };
let input = unsafe { std::slice::from_raw_parts(ctx.json_in_ptr, ctx.json_in_len) };
let Ok(mut value) = serde_json::from_slice::<serde_json::Value>(input) else {
return JSON_MUTATE_UNCHANGED;
};
value["plugin"] = serde_json::Value::Bool(true);
let Ok(out) = serde_json::to_vec(&value) else {
return JSON_MUTATE_UNCHANGED;
};
write_json_output(ctx, &out)
}