I try to create a tree structure in JSON from a MySQL database.
This JSON is used to represent a Path with all its steps
I have to grab data from 5 tables and each one is a level in my JSON tree (in MySQL, One-to-Many relationships permit to build the 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 can't find how to set up the component tWriteJSONField to achieve this. I obtain the correct output for the "Path level", but can't grab children : I only get one child.
I assume, I have to use group by
, loop element
and group element
in the component properties but can't find how to set up them correctly.
I am searching for explanation for this properties to understand how it works and be able to solve my problem.