Json string response after ajax call in cakephp 4.4.11

Normaly I use this

$this->response->getBody()->write(json_encode($array));

from a controller/action,

but is there a better way always to get a json stream back to client???

Thank you for any hint.

Michael

See JSON view example from docs gives "Missing Template error" - #4 by KevinPfeifer

Thanks a lot for this but this is just a response with pane json string as from ajax request.

I’m still have this problem. :frowning:
Michael