To create such a complex JSON structure I would recommend the following steps:
Use Group Loop start node to iterate over categories
Use the JSON to Table node to create JSON objects, excluding the category column using the Row-oriented aggregation direction option
Use the Constant Value Column and the current category value passed with a flow variable to create a cell with the category name
Collect the results with the Loop End node
Finally combine the created objects using the JSON Row Combiner node with the Collect into object with key option and selecting the corresponding category column.
This is the basic algorithm which you can adjust to your needs. Also please find attached a sample workflow.