Create function to handle json responses