Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
How to post-process JSON response in express?

I am building an API with express and JSON middleware. I want to have a generic middleware that wraps each JSON response. The wrapping is an asynchronous process - there is a backend process that asynchronously generates a signature for the given JSON object. Example:

A route:

app.use("/", (req, res) => res.json({status: "ok"}))

The middleware would ideally intercept the JSON response, asynchronously generate a signature and ultimately send the user the following JSON:

{
    "signature": "...",
    "content": { "status": "ok" }
}

What's the best approach to building such a middleware?

I have tried replacing res.json with a custom function. The problem with this solution is that the signature generation is asynchronous, but the res.json is a synchronous function. This was my approach:

export function signatureMiddleware(req, res, next) {
    var json = res.json;
    res.json = async function (obj) {
      json.call(this, await wrapAndSign(obj));
    };
    next();
}
about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!