I am trying to create a tree structure in JSON from a MySQL database.
This JSON is used to represent the Path with all its steps.
I need to capture data from 5 tables, and each of them is a level in my JSON tree (in MySQL, a one-to-many relationship allows you to build a tree).
Here is a simplified version of the expected result:
{
"id": 1,
"name": "Path",
"steps": [
{
"id": 2,
"name": "Step 1",
"children": [
{
"id": 3,
"name": "Step 2"
},
... Other steps of the level
],
}
]
}
I cannot find how to configure the tWriteJSONField component to achieve this. I get the correct conclusion for the "Level of the path", but I can not capture the children: I get only one child.
I assume that I should use group by, loop elementand group elementin the properties of the component, but I can not find how to configure them correctly.
, , .