title: GSON - Creating JSON tree structure from Java
body: <p>Have a couple questions, using GSON. I have a feeling that GSON might not be what I am looking for in terms of a library that will be able to give me a JSON object that I can use later.</p>
  
  <p>I am reading data from a database to populate a json object that I will later use. The output of the json object should look similar to the json below, which involves parents and children. It forms a small tree based structure:</p>
  
  <pre><code>var json = { 
           id: "1", 
           name: "Joe Smith", 
           data: { 
           "email": "",
           "phone": "123-123-1233"},
           children: [{
                          id: "Tim Anderson",
                          name: "Tim Anderson",
                          data: { 
                               "email": "x@gmail.com",
                               "phone": "123-123-1233"
                          },
                          children: []
                      },{
                          id: "Christopher Johnson",
                          name: "Christopher Johnson",
                          data: {  
                               "email": "x@gmail.com",
                               "phone": "123-123-1233"
                          },
                          children: []
                      },{
                          id: "Kate Green",
                          name: "Kate Green",
                          data: {
  
                          },
                          children: [{
                              id: "Gary Jones",
                              name: "Gary Jones",
                              data: {},
                              children: []
                          }, {
                              id: "Melissa Brand",
                              name: "Melissa Brand",
                              data: {},
                              children: []
                          }]
                      }
                      ] 
      }
  </code></pre>
  
  <p>How do I create a GSON object, similar to the structure above, that I can serialize to JSON that has this type of hierarchy? I've tried using maps and other collections - but I am having difficulty getting the results I want. Hence why I ask if GSON is what I really want for a JSON serialization.</p>