HTTP Response withJson() output looks like truncated

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

Until today, I still stuck with this problem .

Please help me

Thank You :slight_smile:

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.