Array to string conversion error with json_encode

You are getting this error as you are trying to echo an array. And you don't wrap a function call in quotes.

replace

echo "json_encode($response)";

with

echo json_encode($response);