add toJson templating function

Add a templating function to allow writing out mongo docs as json into the redis cache