title: Convert a nested struct to nested json dynamically golang
body: <p>how do i convert the following nested struct</p>
  <pre><code>type Details struct {
      name        string
      age         int
      address     *address
      dateOfBirth *date
  }
  
  type address struct {
      street  string
      city    string
      state   string
      country string
  }
  
  type date struct {
      day   int
      month string
      year  int
  }
  
  type StudentDetails struct {
      details *PersonalDetails
  }
  </code></pre>
  <p>to a nested json of any level in golang, something like this</p>
  <pre><code>{
      &quot;Student_1&quot;:{
          &quot;name&quot;:&quot;aaa&quot;,
          &quot;age&quot;:20,
          &quot;address&quot;:[{
              &quot;street&quot;:&quot;&quot;,
              &quot;city&quot;:&quot;&quot;,
              &quot;state&quot;:&quot;&quot;,
              &quot;country&quot;:&quot;&quot;
          },{
              &quot;street&quot;:&quot;&quot;,
              &quot;city&quot;:&quot;&quot;,
              &quot;state&quot;:&quot;&quot;,
              &quot;country&quot;:&quot;&quot;
          }],
          &quot;date&quot;:{
              &quot;day&quot;:1,
              &quot;month&quot;:&quot;Jan&quot;,
              &quot;year&quot;:2000
          }
      },
      &quot;Student_2&quot;:{
          &quot;name&quot;:&quot;bbb&quot;,
          &quot;age&quot;:22,
          &quot;address&quot;:[{
              &quot;street&quot;:&quot;&quot;,
              &quot;city&quot;:&quot;&quot;,
              &quot;state&quot;:&quot;&quot;,
              &quot;country&quot;:&quot;&quot;
          },{
              &quot;street&quot;:&quot;&quot;,
              &quot;city&quot;:&quot;&quot;,
              &quot;state&quot;:&quot;&quot;,
              &quot;country&quot;:&quot;&quot;
          }],
          &quot;date&quot;:{
              &quot;day&quot;:1,
              &quot;month&quot;:&quot;Feb&quot;,
              &quot;year&quot;:2002
          }
      }
  
  }
  </code></pre>
  <p>i want to build a json dynamically based on what is in this struct. The struct is build from protocol buffer. The pointer points to the struct it needs to fetch the details from. I used to reflect package to access the struct, i'm able to read through the data but not able to build the same. Any help is appreciated</p>