Simple but effective way to remove recursively all the annoying $decimal key when using res.json
.
It's a simple regex that cleans the response object as a json before sending.
const express = require('express'); | |
const app = express(); | |
app.use((req, res, next) => { | |
const { json } = res; | |
const fn: any = function (this: any, obj: any) { | |
const REGEXP = /{\s*"\$numberDecimal":\s*"(.+?)"\s*}/g; | |
/* eslint-disable-next-line */ | |
obj = JSON.parse(JSON.stringify(obj).replace(REGEXP, '$1')); | |
json.call(this, obj); | |
}; | |
res.json = fn; | |
next(); | |
}); |