I'm using NextJS API Routes and am building for a tutorial. In both production and development, I want the JSON to be formatted. The original code that does not format the JSON and does include the header I want "application/json" is the following:
export default async function handler(req, res) {
..
const speakers = [{id: 1, name: 'sp1'},{id: 2, name: 'sp2'}];
res.status(200).json(speakers);
I do want to format the JSON and I have tried the following and it does format the JSON but I can't figure out how to attach the content type header "application/json" to the response.
res.status(200).send(JSON.stringify(speakers,null,2));
*** Though I tagged this question with express, I think there is a NextJS specific component to it.