Which JSON Content-Type to Use in Node.js

Written: August 14, 2026 · Updated: August 15, 2026

For JSON APIs, the standard Content-Type is application/json. That tells clients and servers to parse the body as JSON rather than plain text or form data.

In Express, set the header on responses and rely on express.json() (or equivalent) to parse incoming JSON bodies.

Response header example

res.set('Content-Type', 'application/json');
res.status(200).send(JSON.stringify({ ok: true }));
// or simply:
res.status(200).json({ ok: true });

Request parsing

const express = require('express');
const app = express();
app.use(express.json()); // reads application/json bodies
app.post('/api', (req, res) => {
  res.json({ youSent: req.body });
});

Avoid text/json or inventing custom types unless you have a documented legacy constraint. Stick to application/json for modern APIs.

Advertisement

Quick checklist

  • Send Content-Type: application/json; charset=utf-8 when relevant
  • Pair it with Accept: application/json on clients that care
  • Validate JSON shape after parsing—headers alone are not security

Advertisement

Keep learning

If this walkthrough on Which JSON Content-Type to Use in Node.js helped, open the code again and change one input or assumption. Small experiments beat rereading the same example.

Want more step-by-step tutorials like this? Browse blog.xqa.io — and tell us which topic you want next.

Advertisement

Previous Article

Add First N Numbers in C Using a Function

Next Article

How to Make Git Forget a Tracked File After Adding It to .gitignore

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨