title: How can I print out a map[string]interface{} as json?
body: <p>I have a problem with formatting when using <code>sqlx</code> </p>
  
  <pre><code>rows, err = db.Queryx(query)
  for rows.Next() {
      results := make(map[string]interface{})
      err = rows.MapScan(results)
      fmt.Fprintf(w,"%#v \n", results)
  }
  </code></pre>
  
  <p>The output when using <strong>%#v</strong></p>
  
  <pre><code>fmt.Fprintf(w,"%#v \n", results)
  </code></pre>
  
  <blockquote>
    <p>map[string]interface {}{"USER_ID”:”JD”, "USER_NAME”:”John Doe”}</p>
    
    <p>map[string]interface {}{"USER_ID”:”JAD”, "USER_NAME”:”Jane Doe”} </p>
    
    <p>map[string]interface {}{"USER_ID”:”DD”, "USER_NAME”:”Donald Duck”}</p>
  </blockquote>
  
  <p>Using only <strong>%v</strong></p>
  
  <pre><code>fmt.Fprintf(w,"%v \n", results)
  </code></pre>
  
  <blockquote>
    <p>map[USER_ID:JD USER_NAME:John Doe]</p>
    
    <p>map[USER_ID:JAD USER_NAME:Jane Doe]</p>
    
    <p>map[USER_ID:DD USER_NAME:Donald Duck]</p>
  </blockquote>
  
  <p>The desired output is to get rid of <strong>map[string]interface {}</strong></p>
  
  <blockquote>
    <p>{"USER_ID”:”JD”, "USER_NAME”:”John Doe”}</p>
    
    <p>{"USER_ID”:”JAD”, "USER_NAME”:”Jane Doe”} </p>
    
    <p>{"USER_ID”:”DD”, "USER_NAME”:”Donald Duck”}</p>
  </blockquote>
  
  <p>Is this possible?</p>
  
  <p><strong>EDIT USING JSON</strong></p>
  
  <p>According to @Timothy Jones I have updated the main code and it work as expected. Except that the result is printed to the TERMINAL and not browser.</p>
  
  <pre><code>rows, err = db.Queryx(query)
    for rows.Next() {
      results := make(map[string]interface{})
      err = rows.MapScan(results)
      if err := enc.Encode(results); err != nil {
        fmt.Fprintf(w,"%s\n", results)
      }
    }
  </code></pre>
  
  <blockquote>
    <p>{"USER_ID”:”JD”,”USER_NAME”:”John Doe”}</p>
    
    <p>{"USER_ID”:”JAD”,”USER_NAME”:”Jane Doe”}</p>
    
    <p>{"USER_ID”:”DD”,”USER_NAME”:”Donald Duck”}</p>
  </blockquote>
  
  <p>Removing the error handling just to test. It shows wrong results, but are printed to the BROWSER as it should.</p>
  
  <pre><code>rows, err = db.Queryx(query)
  for rows.Next() {
    results := make(map[string]interface{})
    err = rows.MapScan(results)
    enc.Encode(results)
    fmt.Fprintf(w,"%s\n", results)
  }
  </code></pre>
  
  <blockquote>
    <p>map[USER_ID:JD USER_NAME:John Doe] </p>
    
    <p>map[USER_ID:JAD USER_NAME:Jane Doe]</p>
    
    <p>map[USER_ID:DD USER_NAME:Donald Duck]</p>
  </blockquote>
  
  <p>One question remains. How do I print the correct result to the BROWSER?</p>