Here is what my database table schema
Movie (id, movie_name, genre, time, channel)
I have a MySQL
table and want to return a nested json
to an API, grouping them by genre and channel.
For example:
[
'comedy': {
[{'id': 1, 'movie_name': 'm1', 'time': 18:00, 'channel': 'c1'},
{'id': 1, 'movie_name': 'm2', 'time': 18:00, 'channel': 'c2'}]
},
'horror': {
[{'id': 1, 'movie_name': 'm3', 'time': 18:00, 'channel': 'c1'},
{'id': 1, 'movie_name': 'm4', 'time': 18:00, 'channel': 'c2'}]
}
]
And similarly for each channels.
Update: I am not using SQL-Alchemy, all I am doing now is return jsonify(cursor.fetchall())