title: How do I print sql rows in JSON using golang?
body: <p>I understand how to return JSON using the gorilla/mux go package but i want to be able to print JSON also in development without having to wrap it to route endpoint</p>
  <p>I have the following code and want to list users from postgresql database</p>
  <pre><code>package main
  
  import (
      &quot;encoding/json&quot;
      &quot;fmt&quot;
      &quot;gorm.io/driver/postgres&quot;
      &quot;gorm.io/gorm&quot;
  )
  
  var DB *gorm.DB
  var err error
  
  
  const DNS = &quot;host=localhost user=postgres_user password=postgres_password dbname=postgres_db port=5432 sslmode=disable&quot;
  
  
  type User struct {
      gorm.Model
      FirstName string `json:&quot;firstname&quot;`
      LastName  string `json:&quot;lastname&quot;`
      Email     string `json:&quot;email&quot;`
  }
  
  func PostgresTest() {
      DB, err = gorm.Open(postgres.Open(DNS), &amp;gorm.Config{})
      if err != nil {
          fmt.Println(err.Error())
          panic(&quot;Cannot connect to DB&quot;)
      }
      
      var users []User
      
      DB.Limit(2).Find(&amp;users)
      // json.NewEncoder(w).Encode(users)
      fmt.Println(json.Marshal(users))
  
  }
  
  func main() {
      PostgresTest()
  }
  </code></pre>
  <p>here is what am expecting</p>
  <pre><code>[
      {
          &quot;ID&quot;: 1,
          &quot;CreatedAt&quot;: &quot;2021-09-06T14:18:47.766414-05:00&quot;,
          &quot;UpdatedAt&quot;: &quot;2021-09-06T14:18:47.766414-05:00&quot;,
          &quot;DeletedAt&quot;: null,
          &quot;firstname&quot;: &quot;first1&quot;,
          &quot;lastname&quot;: &quot;last1&quot;,
          &quot;email&quot;: &quot;first1.last1@email.com&quot;
      },
      {
          &quot;ID&quot;: 2,
          &quot;CreatedAt&quot;: &quot;2021-09-06T14:18:58.144181-05:00&quot;,
          &quot;UpdatedAt&quot;: &quot;2021-09-06T14:18:58.144181-05:00&quot;,
          &quot;DeletedAt&quot;: null,
          &quot;firstname&quot;: &quot;first2&quot;,
          &quot;lastname&quot;: &quot;last2&quot;,
          &quot;email&quot;: &quot;first2.last2@email.com&quot;
      }
  ]
  </code></pre>
  <p>but here is what am getting</p>
  <pre><code>[91 123 34 73 68 34 58 49 44 34 67 114 101 97 116 101 100 65 116 34 58 34 50 48 50 49 45 48 57 45 48 54 84 48 55 58 50 49 58 49 51 46 53 52 50 54 55 50 45 48 53 58 48 48 34 44 34 85 112 100 97 116 101 100 65 116 34 58 34 50 48 50 49 45 48 57 45 48 54 84 48 55 58 50 49 58 49 51 46 53 52 50 54 55 50 45 48 53 58 48 48 34 44 34 68 101 108 101 116 101 100 65 116 34 58 110 117 108 108 44 34 102 105 114 115 116 110 97 109 101 34 58 34 98 97 98 97 116 117 110 100 101 34 44 34 108 97 115 116 110 97 109 101 34 58 34 98 117 115 97 114 105 34 44 34 101 109 97 105 108 34 58 34 98 98 117 115 97 114 105 64 101 109 97 105 108 46 99 111 109 34 125 93] &lt;nil&gt;
  </code></pre>
  <p>What do i do to be able to print JSON or list of JSON?</p>