I am creating a POST method api end point. I am sending the payload as a JSON string in RAW format from the postman. Then I am doing JSON.parse in my deno app controller. But the output after doing the JSON.parse is still a JSON string.
This is my controller code:
import { IResponse } from '../models/response.ts'
import { IFulllName } from '../models/full-name.ts'
export const printFullName = async (
{ request, response }: { request: any, response: any }) => {
const body = await request.body();
let value = body.value;
console.log(value, '||| value');
console.log(typeof(value), '||| value type');
value = JSON.parse(JSON.stringify(value));
// This should be a JSON object but it still logs as a string
console.log(value, '||| value');
console.log(typeof(value), '||| value type');
}
If I do JSON.parse directly without JSON.stringify, I get a 500 internal server error (no error in the logs as well).
Here is the payload that I have tried:
'{"firstName": "First", "lastName": "Last"}'
Note: I am using oak along with Deno.
What I need is to convert the JSON string into a JSON object in the controller code.
In case there is any inbuilt way of doing so using any oak method, please do suggest.