protected function json()
    {
        $this->before(function ($request) {
            if ($request->getContentType() == 'application/json') {
                $request->setData(json_decode($request->getData(), true));
            }
        });
        $this->after(function ($response) {
            $response->contentType = 'application/json';
            if (isset($_GET['jsonp'])) {
                $response->body = $_GET['jsonp'].'('.json_encode($response->body).');';
            } else {
                $response->body = json_encode($response->body);
            }
        });
    }
protected function json()
    {
        $this->before(function ($request) {
            if ($request->getContentType() == 'application/json') {
                $request->setData(json_decode($request->getData(), true));
            }
        });
        $this->after(function ($response) {
            $response->contentType = 'application/json';
            if (isset($_GET['jsonp'])) {
                $response->body = $_GET['jsonp'].'('.json_encode($response->body).');';
            } else {
                $response->body = json_encode($response->body);
            }
        });
    }
protected function json ( ) { $ this -> before ( function ( $ request ) { if ( $ request -> getContentType ( ) == 'application/json' ) { $ request -> setData ( json_decode ( $ request -> getData ( ) , true ) ) ; } } ) ; $ this -> after ( function ( $ response ) { $ response -> contentType = 'application/json' ; if ( isset ( $ _GET [ 'jsonp' ] ) ) { $ response -> body = $ _GET [ 'jsonp' ] . '(' . json_encode ( $ response -> body ) . ');' ; } else { $ response -> body = json_encode ( $ response -> body ) ; } } ) ; }
Condition method to turn output into JSON.

This condition sets a before and an after filter for the request and response. The
before filter decodes the request body if the request content type is JSON, while the
after filter encodes the response body into JSON.
Condition method to turn output into JSON .