header('application/json');
echo json_encode("<whateverResultStringHere>";
the client (this could be a browser [of which there are quite a few], an app, native software etc) may ignore different types of headers at this point but should they choose to actually do something, you don't want to be caught out.
be proactive in the event various clients eventually start doing something with the different header typesThat's right but it would seem that they are already.
try {
...
}
catch ($e) {
header('application/json')
echo json_encode($e);
}