Reading unknown JSON object in go language

Reading unknown JSON object in go language

Exploring [The Go Language][1] is so much fun. Everything is brand new, and different then any other language. This time I’m going to show quick snippet which shows how to read JSON object with unknown structure, and map elements to something like hash table.

Out JSON object looks pretty simple:

{
    "created_at": null,
    "name": "product name",
    "object_id": 123,
    "price": "$180.91",
    "updated_at": null,
    "url": "http://www.google.com"
}

Let’s GO

func getrecord() {
	body := fetch("http://localhost/our.json")
	var f interface{}
	err := json.Unmarshal(body, &f)
	if err != nil {
		fmt.Println("error:", err)
	}
	fmt.Printf("%+v\n", f)
	m := f.(map[string]interface{})
	fmt.Printf("\n:%s:", m["price"])

}


 [1]: http://golang.org/