I am trying to convert this json-format string into an actual json object in GOLANG.
{"predictions": [{"predictions": [4492.0]}, {"predictions": [4515.84716796875]}, {"predictions": [4464.86083984375]}]}
Basically, it is a dictionary with a key "predictions" and the value es an array of dictionaries (each dictionary is has as a key "predictions" and a value an 1-element float array. I created two structure (one for the first dictionary and the other one for the array of dictionaries), but I can't fit the string json to my structure. I am not sure what I am missing
package main
import (
"encoding/json"
"fmt"
)
type dataPredictions struct {
SinglePredictions *SinglePredictions `json:"predictions"`
}
type SinglePredictions struct {
Predictions []map[string]int `json:predictions`
}
func main() {
s := `{"predictions": [{"predictions": [4492.0]}, {"predictions": [4515.84716796875]}, {"predictions": [4464.86083984375]}]}`
data := &dataPredictions{
SinglePredictions: &SinglePredictions{},
}
err := json.Unmarshal([]byte(s), data)
s2, _ := json.Marshal(data)
fmt.Println(err)
fmt.Println(data.SinglePredictions)
fmt.Println(string(s2))
}
The error I get is below.
json: cannot unmarshal array into Go struct field dataPredictions.predictions of type main.SinglePredictions