Final answer:
The correct method to send a JSON response in Express.js is res.json({ key: 'value' }). It automatically sets the content-type as 'application/json' and correctly handles different data types to ensure a valid JSON response.
Step-by-step explanation:
If 'res' is the response object of an incoming request, the correct function to send a response in JSON format among the given options is res.json({ key: 'value' }). This function is a method provided by Express.js, a web application framework for Node.js, designed specifically for sending JSON responses. When res.json is called, it sends a response (with the correct content-type 'application/json') that is the JSON representation of the provided object or array.
Using res.json is the standard way to send JSON responses in Express applications. It not only sets the content type to 'application/json' but also converts non-objects, such as null or undefined, which are not valid JSON, into a valid JSON response.