4

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.

рüффп
  • 5,172
  • 34
  • 67
  • 113
Elorfin
  • 2,487
  • 1
  • 27
  • 50

1 Answers1

1

I have found nice blogpost describing solution to your problem http://blog.wdcigroup.net/tag/twritejsonfield/?NSID=ZuQZmq

Basically you need to select "Steps" as "group element" and "children" as "loop element" in json tree. Then if select company's "Id" as group by column in tWriteJSONCOlumn element.

I have also tried to create TOS job solving suggested scenario and you can download it here https://www.dropbox.com/s/cp7puxerylhpasl/TEST.zip

Hope this helps you

Petr

Petr Chudanic
  • 547
  • 4
  • 12