If you create a servletContextListener you can use it to add a new filter which runs as part of the forward request. You can then implement a HttpServletResponseWrapper which overrides the getPrintWriter() and getOutputStream() methods to return your own objects which basically buffer what is written, and then replace the response object with your wrapper before you call doChain() in your new filter. Then on return from doChain you pull the response data from your buffer, process it how you like and then write it out using a PrintWriter or OutputStream (whichever was used by the rest request). I suspect that the rest service will use a PrintWriter for output so that would be the route that you take.
There is great example of how to do this (minus the ServletContextListener) here:
http://www.java2s.com/Tutorial/Java/0400__Servlet/Filterthatusesaresponsewrappertoconvertalloutputtouppercase.htm
Where this example converts the response to upper case is where you look for the json name,value pair which you need to change and then modify it as needed.
Here is an example of a suitable ServletContextListener. Note that the listener needs to be added such that it is called for all apps and different server implementations provide different methods for doing this:
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
@WebListener
public class ServletContextListenerFilter implements ServletContextListener {
public ServletContextListenerFilter() {}
@Override
public void contextDestroyed(ServletContextEvent arg0) {}
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext sc = sce.getServletContext();
if (sc.getServletContextName().equals("Third party rest serice context name")) {
sc.addFilter("FilterName", filterClass);
}
}
}