I have a JSON object, something like this:
{
    "randomstring": {
        "everything": "here",
        "is": "known"
    }
}
Basically everything inside the randomstring object is known, I can model that, but the randomstring itself is random. I know what it's going to be, but it's different every time. Basically all the data I need is in the randomstring object. How could I parse this kind of JSON to get the data?
Use a map where the key type is string and the value type is a struct with the fields you want, like in this example on the Playground and below:
package main
import (
    "encoding/json"
    "fmt"
    "log"
)
type Item struct{ X int }
var x = []byte(`{
    "zbqnx": {"x": 3}
}`)
func main() {
    m := map[string]Item{}
    err := json.Unmarshal(x, &m)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(m)
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With