Open In App

Difference between res.send() and res.json() in Express

Last Updated : 06 Feb, 2024
Like Article


res.send() is a method used to send a response back to the client. It’s a versatile function that can handle various types of responses, such as HTML, plain text, or even binary data. When you use res.send(), Express automatically sets the appropriate Content-Type header based on the type of data you’re sending.


res.json() is a function that helps send a response in the form of JSON (JavaScript Object Notation) to the client. When you use this function, it automatically sets the type of content in the response to be JSON and sends the provided JavaScript object as the body of the response. This is particularly useful when your server needs to communicate with clients or other services in a structured and standardized data format.

res.send() res.json()
it is versatile, used for various response types. It is specifically designed for sending JSON responses.
It handles plain text, HTML, and other types. it converts JavaScript objects/arrays to JSON format.
It automatically set based on provided data. It automatically set to application/json.
Example : javascript res.send('Text response'); Example: javascript res.json({ key: 'value' });

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads