0

I got a response from redash as follows:

{'PP_DOM': '{"DEFAULT":100}',....................., 'Myst':'["a","b","c","d"]',
  • I want to unmarshal "myst" key's value as a list in golang.I am newbie here.
skysoft999
  • 540
  • 1
  • 6
  • 27

1 Answers1

1

You can unmarshall into map[string]interface{} if you have an unknown data structure to explore it. you then may later want to define a struct which maps to the data properly. So to get started, use something like this:

    var jsonData = []byte(`{"PP_DOM": {"DEFAULT":100},"Myst":["a","b","c","d"]}`)
    var data map[string]interface{}
    err := json.Unmarshal(jsonData, &data)
    if err != nil {
        fmt.Println("json: error decoding", err)
    }
    fmt.Printf("Myst:%+v", data["Myst"])

https://play.golang.org/p/V5GBtLH6oLs

Your json doesn't appear to be valid, better to post what you have tried instead, which should at least involve valid json.

You should take a look at the docs for the json pkg, in particular the examples.

Kenny Grant
  • 9,360
  • 2
  • 33
  • 47