title: how I can mapping complex JSON to other JSON
body: <p>I am trying to build <em>aggregation services</em>, to all third party APIs that's I used,
  this <em>aggregation services</em> taking json values coming from my main system and it will put this value to key equivalent to third party api key then, <em>aggregation services</em> it will send request to third party api with new json format.</p>
  <p>example-1:</p>
  <pre><code>package main
  
  import (
      &quot;encoding/json&quot;
      &quot;fmt&quot;
      &quot;log&quot;
  
      &quot;github.com/tidwall/gjson&quot;
  )
  
  func main() {
      // mapping JSON
      mapB := []byte(`
      {
          &quot;date&quot;: &quot;createdAt&quot;,
          &quot;clientName&quot;: &quot;data.user.name&quot;
      }
      `)
  
      // from my main system
      dataB := []byte(`
      {
          &quot;createdAt&quot;: &quot;2017-05-17T08:52:36.024Z&quot;,
          &quot;data&quot;: {
              &quot;user&quot;: {
                  &quot;name&quot;: &quot;xxx&quot;
              }
          }
      }
      `)
  
      mapJSON := make(map[string]interface{})
      dataJSON := make(map[string]interface{})
      newJSON := make(map[string]interface{})
  
      err := json.Unmarshal(mapB, &amp;mapJSON)
      if err != nil {
          log.Panic(err)
      }
  
      err = json.Unmarshal(dataB, &amp;dataJSON)
      if err != nil {
          log.Panic(err)
      }
  
      for i := range mapJSON {
          r := gjson.GetBytes(dataB, mapJSON[i].(string))
          newJSON[i] = r.Value()
      }
  
      newB, err := json.MarshalIndent(newJSON, &quot;&quot;, &quot;  &quot;)
      if err != nil {
          log.Println(err)
      }
  
      fmt.Println(string(newB))
  }
  </code></pre>
  <p>output:</p>
  <pre><code>{
    &quot;clientName&quot;: &quot;xxx&quot;,
    &quot;date&quot;: &quot;2017-05-17T08:52:36.024Z&quot;
  }
  </code></pre>
  <p>I use <a href="https://github.com/tidwall/gjson" rel="nofollow noreferrer">gjson</a> package to get values form my main system request in simple way from a json document.</p>
  <p>example-2:</p>
  <pre><code>import (
      &quot;encoding/json&quot;
      &quot;fmt&quot;
      &quot;log&quot;
  
      &quot;github.com/tidwall/gjson&quot;
  )
  
  func main() {
      // mapping JSON
      mapB := []byte(`
      {
          &quot;date&quot;: &quot;createdAt&quot;,
          &quot;clientName&quot;: &quot;data.user.name&quot;,
          &quot;server&quot;:{
              &quot;google&quot;:{
                  &quot;date&quot; :&quot;createdAt&quot;
              }
          }
      }
      `)
  
      // from my main system
      dataB := []byte(`
      {
          &quot;createdAt&quot;: &quot;2017-05-17T08:52:36.024Z&quot;,
          &quot;data&quot;: {
              &quot;user&quot;: {
                  &quot;name&quot;: &quot;xxx&quot;
              }
          }
      }
      `)
  
      mapJSON := make(map[string]interface{})
      dataJSON := make(map[string]interface{})
      newJSON := make(map[string]interface{})
  
      err := json.Unmarshal(mapB, &amp;mapJSON)
      if err != nil {
          log.Panic(err)
      }
  
      err = json.Unmarshal(dataB, &amp;dataJSON)
      if err != nil {
          log.Panic(err)
      }
  
      for i := range mapJSON {
          r := gjson.GetBytes(dataB, mapJSON[i].(string))
          newJSON[i] = r.Value()
      }
  
      newB, err := json.MarshalIndent(newJSON, &quot;&quot;, &quot;  &quot;)
      if err != nil {
          log.Println(err)
      }
  
      fmt.Println(string(newB))
  }
  </code></pre>
  <p>output:</p>
  <pre><code>panic: interface conversion: interface {} is map[string]interface {}, not string
  </code></pre>
  <p><em>I can handle this error by using  <a href="https://golang.org/ref/spec#Type_assertions" rel="nofollow noreferrer">https://golang.org/ref/spec#Type_assertions</a>, but what if this json object have array and inside this array have json object ....</em></p>
  <p><strong>my problem is I have different apis, every api have own json schema, <em>and my way for mapping json only work if
  third party api have json key value only, without nested json or array inside this array json object.</em></strong></p>
  <p>is there a way to mapping complex json schema, or golang package to help me to do that?</p>