Tag: JSON

json: cannot unmarshal object into Go struct field

Problem json: cannot unmarshal object into Go struct field Code package main import ( “encoding/json” “fmt” ) // DTO object type mould struct { Particle tiny } type tiny interface { GetName() string } // Implement the interface type speck struct { Name string `json:”name”` } func (s *speck) GetName() string { return s.Name }…

Go, gorm, nested JSON and associations

Go, gorm, nested JSON and associations gorm provides a clean way to store a nested JSON with the relation of associations among tables. The following code creates a DB with three levels of nesting. package main import ( “encoding/json” “fmt” “github.com/jinzhu/gorm” _ “github.com/lib/pq” ) const ( host = “localhost” port = 5432 user = “postgres”…