I am using the Slim framework with PHP to create a RESTful API for my app. However, I assumed that the framework would have some way of creating easier JSON outputs rather than
You can use in slim3, Slim’s Response object custom method withJson($data, $status, $encodingOptions)
$app->get('/hello/{name}', function ($request, $response, $args) {
$data['msg']='Hello '.$request->getAttribute('name');
$newResponse = $response->withJson($data);
});
For more information read here.