Here’s a much leaner solution to the same problem, bypassing the built-in ZF action helper (which calls the view helper with the same name, which calls Zend_Json and does way too many smart things for my tastes):

[geshi lang=php]
class My_Controller_Action_Helper_Json extends Zend_Controller_Action_Helper_Abstract
{
/**
* Strategy pattern: call helper as helper broker method
*
* Sends a JSON-encoded response with the payload
*
* @param array $payload
*
* @return string|false
*/
public function direct(array $payload)
{
$json = json_encode($payload);
$response = Zend_Controller_Front::getInstance()->getResponse();
$response->setHeader(‘Content-Type’, ‘application/json’);
$response->setBody($json);
return $json;
}
}
[/geshi]

Make sure noViewRenderer is set to true in the front controller.