# \[solved\] withJson($array) returns null

**URL:** <https://discourse.slimframework.com/t/solved-withjson-array-returns-null/2340>\
**Category:** Questions\
**Created:** [April 12, 2018, 1:54pm UTC](https://discourse.slimframework.com/t/solved-withjson-array-returns-null/2340 "2018-04-12T13:54:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrian007](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@adrian007](https://discourse.slimframework.com/u/adrian007)\
**Post date:** [April 12, 2018, 1:54pm UTC](https://discourse.slimframework.com/t/solved-withjson-array-returns-null/2340/1 "2018-04-12T13:54:26Z")

</div>

Hi, I am returning a simple array:

`return ['ABC' => 'DEF'];`

which passes through the CoreFunctions, more explicitly `$response->withJson($resp)` .

I am expecting a JSON object returned in the format:

```
{
   "ABC": "DEF"
}

```

But I get nothing back (and the response header is set to `text/html; charset=UTF-8`) .

However, if I run

`return json_encode(['ABC' => 'DEF']);`

then I get the expected outcome.

I thought -\>withJson would do the above, or is this expected behaviour? (I’m running Slim 3.9.2)

---

<div class="post-metadata">

**Author:** ![mzc](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@mzc](https://discourse.slimframework.com/u/mzc)\
**Post date:** [April 12, 2018, 2:15pm UTC](https://discourse.slimframework.com/t/solved-withjson-array-returns-null/2340/2 "2018-04-12T14:15:50Z")

</div>

I test your case, I get the expected JSON doing:

```
 $app->get('/test/', function (Request $request, Response $response, array $args) {
    $a = ['abc'=>'def'];
    return $response->withJson($a);
});

```

the header is:

`Content-Type:application/json;charset=utf-8`

---

<div class="post-metadata">

**Author:** ![adrian007](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@adrian007](https://discourse.slimframework.com/u/adrian007)\
**Post date:** [April 12, 2018, 4:59pm UTC](https://discourse.slimframework.com/t/solved-withjson-array-returns-null/2340/3 "2018-04-12T16:59:15Z")

</div>

Thank you @mzc, with your help I managed to pinpoint the issue. I was pushing all requests through a route resolver, and that’s what was causing the unexpected behaviour.

All sorted now, thanks again 😄

---

<div class="post-metadata">

**Author:** ![mzc](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@mzc](https://discourse.slimframework.com/u/mzc)\
**Post date:** [April 12, 2018, 8:04pm UTC](https://discourse.slimframework.com/t/solved-withjson-array-returns-null/2340/4 "2018-04-12T20:04:33Z")

</div>

No problem! 🙂
