(09-26-2021, 03:26 AM)InsiteFX Wrote: No sample code, but you can look at filters in the CodeIgniter 4 User Guide. Also take a look at the HTTP responses.
Thanks for the tip, I have solved that by below filter:
Register in
$global 'after' App/Filters.php
Code:
<?php
namespace App\Filters;
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
class JsonFilter implements FilterInterface
{
function __construct()
{
}
public function before(RequestInterface $request, $arguments = null)
{
}
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
$json = $response->getJSON();
$body = preg_replace('/,\s*"[^"]+": null|"[^"]+": null,?/', '', $json);
$response->setJSON($body);
}
}