I have a json data that looks like this:
[ { lat: "41.189301799999996", lon: "11.918255998031015", display_name: "Some place", address: { address: "Address", country: "Country", country_code: "CC" }, geojson: { type: "Polygon", coordinates: [ [ [14.4899021,41.4867039], [14.5899021,41.5867039], ] ] } } ] I would like to parse this data, take the first element from this array and transform it into a new struct that would look like this:
type Location struct { Name string Country string CountryCode string Center Coordinate Coordinates []Coordinate } I have defined Coordinate type like this:
type Coordinate struct { Lat string `json:"lat"` Lng string `json:"lon"` } But, if try to parse this like this:
bytes, err := ioutil.ReadAll(res.Body) if err != nil { http.Error(w, err.Error(), http.StatusBadRequest) } var locations [0]Location if err := json.Unmarshal(bytes, &locations); err != nil { fmt.Println("Error parsing json", err) } fmt.Println(locations) But, that gives me this in the terminal:
[{ { } []}] How can I parse this kind of json structure and transform it to the location kind of structure?