title: merge two JSON arrays with a common key golang
body: <p>it's days I try to merge two jons based on a common key. I have in input two different JSONs with a common field, I would like to merge the data of the two json based on the common key. A sort of sql join between the two JSON.</p>
  
  <p>JSON derives from this code</p>
  
  <pre><code>func Dati_plus(c *gin.Context) {
  
  oracle, err := http.Get("http://XXXX/XXX")
      if err != nil {
              panic(err)
      }
  defer oracle.Body.Close()
  
  mysql, err := http.Get("http://XXXX/XXX")
  if err != nil {
          panic(err)
  }
  defer mysql.Body.Close()
  
  oracleJSON, err := ioutil.ReadAll(oracle.Body)
  if err != nil {
          panic(err)
  }
  mysqlJSON, err := ioutil.ReadAll(mysql.Body)
  if err != nil {
          panic(err)
  }
  
  var oracleOUT map[string]interface{}
  var mysqlOUT map[string]interface{}
  
  json.Unmarshal([]byte(oracleJSON), &amp;oracleOUT)
  json.Unmarshal([]byte(mysqlJSON), &amp;mysqlOUT)
  
  a := map[string]interface{}{"result":mysqlOUT["result"]}
  b := map[string]interface{}{"result":oracleOUT["result"]}
  </code></pre>
  
  <p>the JSONs in input have this form</p>
  
  <pre><code>{"count":2,"result":[{"DESC":"2","NOMEmy":"PIPPO","COGNOMEmy":"PIPPO"},{"DESC":"7","NOMEmy":"PIPPO","COGNOMEmy":"PIPPO"}]
  
  {"count":2,"result":[{"DESC":"2","COS":"PIPPO","ROS":"PIPPO"},{"DESC":"7","COS":"PIPPO","ROS":"PIPPO"},{"DESC":"60","COS":"PIPPO","ROS":"PIPPO"}]
  </code></pre>
  
  <p>If i have two json like this the result of the function it should be</p>
  
  <pre><code>{"count":2,"result":[{"DESC":"2","COS":"PIPPO","ROS":"PIPPO","NOMEmy":"PIPPO","COGNOMEmy":"PIPPO"},{"DESC":"7","COS":"PIPPO","ROS":"PIPPO","NOMEmy":"PIPPO","COGNOMEmy":"PIPPO"},{"DESC":"60","COS":"PIPPO","ROS":"PIPPO"}]
  </code></pre>
  
  <p>if it can help, this is a function I use for merge between two single-value JSONs, but I could not modify it in the right way</p>
  
  <pre><code>    func merge(dst, src map[string]interface{}, depth int) map[string]interface{} {
      if depth &gt; MaxDepth {
          panic("Troppo Lungo")
      }
      for key, srcVal := range src {
          if dstVal, ok := dst[key]; ok {
              srcMap, srcMapOk := mapify(srcVal)
              dstMap, dstMapOk := mapify(dstVal)
              if srcMapOk &amp;&amp; dstMapOk {
                  srcVal = merge(dstMap, srcMap, depth+1)
              }
          }
          dst[key] = srcVal
      }
      return dst
  }
  
      func mapify(i interface{}) (map[string]interface{}, bool) {
          value := reflect.ValueOf(i)
          if value.Kind() == reflect.Map {
              m := map[string]interface{}{}
              for _, k := range value.MapKeys() {
                  m[k.String()] = value.MapIndex(k).Interface()
              }
              return m, true
          }
          return map[string]interface{}{}, false
      }
  </code></pre>
  
  <p>Please, Help Me. THX</p>