headers->set('Content-Type', 'application/json'); // Setting the response body $response->setContent(json_encode(['name' => 'John', 'age' => 30])); // Sending the response object $response->send(); ?>In the example above, the self setBody method is used to set the response content to a JSON object. The JSON object is created using the `json_encode()` function which converts a PHP array into a JSON string. The response headers are also set to specify that the response should be sent back in the JSON format. Package Library: Symfony\Component\HttpFoundation\Response This example is based on the Symfony framework, which provides the Response class and the setBody method as part of its HttpFoundation component. This component is used for building HTTP responses in PHP-based web applications.