# HTTP Response withJson() output looks like truncated

**URL:** <https://discourse.slimframework.com/t/http-response-withjson-output-looks-like-truncated/196>\
**Category:** Questions\
**Created:** [May 1, 2016, 12:47pm UTC](https://discourse.slimframework.com/t/http-response-withjson-output-looks-like-truncated/196 "2016-05-01T12:47:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![okaprinarjaya](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/okaprinarjaya/32/83_2.png) [@okaprinarjaya](https://discourse.slimframework.com/u/okaprinarjaya)\
**Post date:** [May 1, 2016, 12:47pm UTC](https://discourse.slimframework.com/t/http-response-withjson-output-looks-like-truncated/196/1 "2016-05-01T12:47:07Z")

</div>

Hi Folks,

I get this response:  
`Expected ',' instead of ''`

When I doing return `$response->withJson($my_array_data, 200);`

But, IF i turn $my\_array\_data into simple array structure, i get normal good json response. Example:  
`return $response->withJson(['resp' => ['attr_one' => 'value one', 'long_long_long_long_fieldname' => 'good value']], 200);`

Then today I use dirty way to produce json response . `echo json_encode($array); exit(0);`

```
$app->get('/acak-rt/{phoneId}', function ($request, $response, $args) {

$q_srv_phone = $this->db->createQueryBuilder()
->select('p.survei_daftar_desa_id')
->from('survei_phone', 'p')
->where('p.master_phone_id = :phoneId')
->setParameter(':phoneId', $args['phoneId'])
->execute();

$srv_phone = $q_srv_phone->fetch();

$q_acak_rt = $this->db->createQueryBuilder()
->select(
    'rt.survei_acak_rt_id',
    'rt.survei_daftar_desa_id',
    'rt.sigma',
    'rt.nilai_acak',
    'rt.terpilih'
)
->from('survei_acak_rt', 'rt')
->where('rt.survei_daftar_desa_id = :desaId')
->orderBy('rt.survei_acak_rt_id', 'ASC')
->setParameter(':desaId', $srv_phone['survei_daftar_desa_id'])
->execute();

$acak_rt = $q_acak_rt->fetchAll();

echo json_encode($acak_rt);
exit(0);

```

});  
`

Would you like to help me to test my serialized array ? you can dowload here:  
[http://s000.tinyupload.com/index.php?file\_id=09206376323751810777](http://s000.tinyupload.com/index.php?file_id=09206376323751810777)

Until today, I still stuck with this problem .

Please help me

Thank You 🙂

---

<div class="post-metadata">

**Author:** ![llvdl](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.slimframework.com/llvdl/32/78_2.png) [@llvdl](https://discourse.slimframework.com/u/llvdl)\
**Post date:** [May 1, 2016, 9:54pm UTC](https://discourse.slimframework.com/t/http-response-withjson-output-looks-like-truncated/196/2 "2016-05-01T21:54:50Z")

</div>

I tried the following and it seems to work fine (in Slim 3):

```
$app->get('/test', function($request, $response, $args) {
        $data = '...'; // data you provided in downloadable text file
        $my_array_data = unserialize($data);
        return $response->withJson($my_array_data, 200);
});

```

Note that in the text file there is a leading spacing before the first character and some spaces afterwards. If I leave those in, than I get the following error:

```
PHP Notice: unserialize(): Error at offset 0 of 21541 bytes

```

But since that is not the error you got, it is probably something else. If `$acak_rt` is an array, then

```
return $response->withJson($acak_rt, 200);

```

should work.
