How does express splice json returns?

  node.js, question

I use nodejs to write the server. If I want to return the objects I checked from the database inside, I use res.json(doc) directly, but if I want to add a field message:sucess to json. How to express success?
Is that I want all requests to return json with a message field?

The most convenient way:

res.json(JSON.stringify({data: doc, message: success}))

However, it will be very annoying to always write like this, and you will gradually optimize your writing style.

function toJSON (data = {}, message = '', status = '', code = '') {
 return {
 JSON.stringify({ data, message, status, code })