# JSON expected, but getting error "view missing"

**URL:** <https://discourse.cakephp.org/t/json-expected-but-getting-error-view-missing/1970>\
**Category:** Need Help\
**Created:** [February 2, 2017, 6:32am UTC](https://discourse.cakephp.org/t/json-expected-but-getting-error-view-missing/1970 "2017-02-02T06:32:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ooypunk](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Ooypunk](https://discourse.cakephp.org/u/Ooypunk)\
**Post date:** [February 2, 2017, 6:32am UTC](https://discourse.cakephp.org/t/json-expected-but-getting-error-view-missing/1970/1 "2017-02-02T06:32:14Z")

</div>

On a fresh install of 3.3.12, I tried to get JSON data from my project. According to the manual, putting this in my function (controller action) should be enough, except that I keep getting a “view missing” error.

```auto
public function jsonGet() {
	// Set the view vars that have to be serialized.
	$this->set('tags', $this->paginate());
	// Specify which view vars JsonView should serialize.
	$this->set('_serialize', ['tags']);
}
```

AppController::initialize() looks like this:

```auto
public function initialize() {
    parent::initialize();
    
    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
}
```

In the request an Accept-header is sent, with “application/json, text/javascript, _/_; q=0.01”.

What am I missing?

---

<div class="post-metadata">

**Author:** ![egalles79](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/egalles79/32/507_2.png) [@egalles79](https://discourse.cakephp.org/u/egalles79)\
**Post date:** [February 4, 2017, 9:08am UTC](https://discourse.cakephp.org/t/json-expected-but-getting-error-view-missing/1970/2 "2017-02-04T09:08:13Z")

</div>

I usually return this:

//Return the status code  
$this-\>response-\>statusCode(201);  
//then:  
return json\_encode(value);

---

<div class="post-metadata">

**Author:** ![Ooypunk](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Ooypunk](https://discourse.cakephp.org/u/Ooypunk)\
**Post date:** [February 5, 2017, 6:46pm UTC](https://discourse.cakephp.org/t/json-expected-but-getting-error-view-missing/1970/3 "2017-02-05T18:46:41Z")

</div>

Then I get the error message “Controller actions can only return Cake\Network\Response or null.”.

---

<div class="post-metadata">

**Author:** ![egalles79](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/egalles79/32/507_2.png) [@egalles79](https://discourse.cakephp.org/u/egalles79)\
**Post date:** [February 5, 2017, 10:25pm UTC](https://discourse.cakephp.org/t/json-expected-but-getting-error-view-missing/1970/4 "2017-02-05T22:25:50Z")

</div>

> [@Ooypunk](#):
>
> Controller actions can only return Cake\Network\Response or null.

> <https://stackoverflow.com/questions/37227851/cakephp-3-ajax-request-response-from-controller-action>

---

<div class="post-metadata">

**Author:** ![Ooypunk](https://avatars.discourse-cdn.com/v4/letter/o/96bed5/32.png) [@Ooypunk](https://discourse.cakephp.org/u/Ooypunk)\
**Post date:** [February 6, 2017, 7:48am UTC](https://discourse.cakephp.org/t/json-expected-but-getting-error-view-missing/1970/5 "2017-02-06T07:48:49Z")

</div>

Thanks for the pointer. I had found it, but as the question is not answered there, I am asking here.

As I see it, the poster on SO has the same problem as I have: though the old methods work, the current documentation says there are other, more modern ways, but seems faulty in explaining how they should work.
