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);
            }
        });
    }