go - Unmarshal JSON with unknown field name -


i have json object, this:

{     "randomstring": {         "everything": "here",         "is": "known"     } } 

basically inside randomstring object known, can model that, randomstring random. know it's going be, it's different every time. data need in randomstring object. how parse kind of json data?

use map key type string , value type struct fields want, in this example on playground , 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) } 

Comments

Popular posts from this blog

php - Autoloader issue not returning Class -

java - How to put two numbers separated by a space into two different arrays -

python - matplotlib equivalent for Ubuntu servers with no GUI? -