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()
->from('survei_phone', 'p')
->where('p.master_phone_id = :phoneId')
->setParameter(':phoneId', $args['phoneId'])

$srv_phone = $q_srv_phone->fetch();

$q_acak_rt = $this->db->createQueryBuilder()
->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'])

$acak_rt = $q_acak_rt->fetchAll();

echo json_encode($acak_rt);


Would you like to help me to test my serialized array ? you can dowload here:

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.