NodeJS/Knex Creating Json Response

Clash Royale CLAN TAG#URR8PPPNodeJS/Knex Creating Json Response
I'm currently using NodeJS with knex (Postgresql) for database stuff.
Problem:
Imagine the following two tables in database:
Table 1
PROJECT
id (pk)
name
Table 2
EMPLOYEE
id (pk)
name
project_id (fk)
I want to create a json-response to the user that looks like the following:
{
projects: [
{
id: 1,
name: 'emxample 1',
employees: [
{
id: 1,
name: 'example 1'
},
{
id: 2,
name: 'example 2'
}
]
}
]
}
and so on.
Making a query like:
knex('projects').select('projects.*', 'employee.*').join('employee', 'employee.project_id', '=', 'project.id')
And using res.json()
does not returns an array of employees.
res.json()
employees
What is the way to go to achieve that?
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.