private function writeJson(
        ResponseInterface $response,
        $json,
        int $code = 200
    ): ResponseInterface {
        if ($json instanceof \JsonSerializable) {
            $json = $json->jsonSerialize();
        }

        if (is_array($json) && isset($json['status'])) {
            $code = $json['status'];
        }

        $response->getBody()->write(json_encode($json));

        return $response->withStatus($code)->withHeader(
            'Content-Type',
            'application/json'
        );
    }
private function writeJson(
        ResponseInterface $response,
        $json,
        int $code = 200
    ): ResponseInterface {
        if ($json instanceof \JsonSerializable) {
            $json = $json->jsonSerialize();
        }

        if (is_array($json) && isset($json['status'])) {
            $code = $json['status'];
        }

        $response->getBody()->write(json_encode($json));

        return $response->withStatus($code)->withHeader(
            'Content-Type',
            'application/json'
        );
    }
private function writeJson ( ResponseInterface $ response , $ json , int $ code = 200 ) : ResponseInterface { if ( $ json instanceof \ JsonSerializable ) { $ json = $ json -> jsonSerialize ( ) ; } if ( is_array ( $ json ) && isset ( $ json [ 'status' ] ) ) { $ code = $ json [ 'status' ] ; } $ response -> getBody ( ) -> write ( json_encode ( $ json ) ) ; return $ response -> withStatus ( $ code ) -> withHeader ( 'Content-Type' , 'application/json' ) ; }
Generate JSON response.

@param ResponseInterface $response
@param mixed             $json
@param int               $code

@return ResponseInterface
Generate JSON response .