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

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -