How do I convert a Nest request object with a buffer into JSON? Everything I've logged either shows an array of bytes or a string.
Here is my controller:
export class KycresultsController {
@Post()
create(@Body() data: any): string {
const j = data.toJSON();
var buf = Buffer.from(JSON.stringify(data));
var temp = JSON.parse(buf.toString());
var f = temp.data;
console.log(f);
const decodedJsonObject = Buffer.from(f, 'base64').toString('ascii');
console.log(decodedJsonObject);`
And I send this POST:
curl -X POST localhost:3001/kycresults -d "emsample=1&data=2"
I see in my logs:
[
101, 109, 115, 97, 109, 112,
108, 101, 61, 49, 38, 100,
97, 116, 97, 61, 50
]
emsample=1&data=2
[
101, 109, 115, 97, 109, 112,
108, 101, 61, 49, 38, 100,
97, 116, 97, 61, 50
]
emsample=1&data=2
I want to get {emsample: 1, data: 2}