In Python you can do something like this:
r = requests.get(\"http://wikidata.org/w/api.php\", params=params)
data = r.json()
And now data
I prefer to add a type declaration, that way you can add methods to simplify the type assertions:
package main
import (
"encoding/json"
"log"
"net/http"
"net/url"
)
type Map map[string]interface{}
func (m Map) M(s string) Map {
return m[s].(map[string]interface{})
}
func (m Map) N(s string) float64 {
return m[s].(float64)
}
func main() {
v := url.Values{}
v.Set("action", "wbgetentities")
v.Set("format", "json")
v.Set("ids", "Q24871")
resp, e := http.Get("https://www.wikidata.org/w/api.php?" + v.Encode())
if e != nil {
log.Fatal(e)
}
data := Map{}
json.NewDecoder(resp.Body).Decode(&data)
pageid := data.M("entities").M("Q24871").N("pageid")
println(pageid == 28268)
}
https://golang.org/ref/spec#Type_declarations