I don’t have example code other than the basic middleware template you can find here: https://strapi.io/documentation/developer-docs/latest/concepts/middlewares.html#example
Basically try console.log(ctx.response) after the await next() in which you can then modify the ctx.response with your own structure.
Middlewares run on the request chain (every request, including the admin) so you will have to be careful not to modify the requests for the Admin panel as these can throw errors since the Admin isn’t expecting that format.