Welcome Guest, Not a member yet? Register   Sign In
How to return pure json
#1

(This post was last modified: 01-03-2021, 05:16 AM by chanyui.)

Hello,

I want to respond with json without spaces or line breaks.
This is because the size of the large json grows unnecessarily.




PHP Code:
  public function testapi()
  {
    $data = ['test1' => 1'test2'=> 2];
    return $this->response->setJSON($data);
  


response

Code:
{
    "test1": 1,
    "test2": 2
}


Is there a good way?
Reply
#2

Have you tried with your environment set to production? It looks like it will not "pretty print" json in production. I don’t know if there’s a way to change this.
https://github.com/codeigniter4/CodeIgni...er.php#L65
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
Reply
#3

When I put it in production mode, the problem was solved.
Thank you!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB