ZF2-183: Zend\View\Renderer\JsonRenderer -> recurseModel() returns Zend\View\Variables instead of an array


 * Retrieve values from a model and recurse its children to build a data structure
 * @param  Model $model 
 * @return array

The recurseModel(Model $model) function in Zend\View\Renderer\JsonRenderer does not return an array. instead it returns:

Zend\View\Variables Object
    [strictVars:protected] => 
    [storage:ArrayObject:private] => Array
            [content] => Array
                    [test] => json



class Module implements AutoloaderProvider {

    public function init(Manager $moduleManager) {
        $events = StaticEventManager::getInstance();
        $events->attach('bootstrap', 'bootstrap', array($this, 'initializeView'), 100);
        $events->attach('bootstrap', 'bootstrap', array($this, 'initializeJsonView'));
    public function initializeJsonView($e) {
        $app          = $e->getParam('application');
        $locator      = $app->getLocator();
        $view         = $locator->get('Zend\View\View');
        $jsonStrategy = $locator->get('Zend\View\Strategy\JsonStrategy');

    public function initializeView($e) {
                $app = $e->getParam('application');
                $basePath = $app->getRequest()->getBasePath();
                $locator = $app->getLocator();
                $renderer = $locator->get('Zend\View\Renderer\PhpRenderer');

class UserController extends ActionController {

    public function indexAction() {
        return array('json' => 'test');


Code tags added.

Added testing code

It looks like this has been fixed in recent git versions, though it still outputs the view's 'captureTo' as a key if the controller returns a normal ViewModel (ie something like {'content':{'json':'test'}}).

Returning a JsonModel works as expected (it's got captureTo set to null), but that kind of defeats the purpose of overriding the renderer in the first place. See:

According to the comments this issue is fixed