0

I am using express for my REST API and when I get objects it returns me wrapped array. I would like to have it returned as simple array.

My code looks like that:

router.get('/objects', async (req: Request, res: Response) => {
const objects = await getConnection()
    .getRepository(Object)
    .createQueryBuilder("object")
    .getMany();
return res.status(OK).json({objects});

});

It returns:

{
 objects: [
  {
    id: "11",
    name: "Eleven"
  },
  {
    id: "12",
    name: "Twelve"
  }
 ]
}

I want to have

  {
    id: "11",
    name: "Eleven"
  },
  {
    id: "12",
    name: "Twelve"
  }
0

1 Answer 1

2

Just:

return res.status(OK).json(objects);

you should remove the {} from {objects}

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Ghost, simple and quick answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.