I am attempting to parse some JSON using this API endpoint.
https://www.cryptocompare.com/api/data/coinlist/
I can see it's making the request fine, I then try to decode the body of the response and it comes back with loads of random numbers.
If I copy the body value from my debugger I get the below.
<[]uint8> (length: 643401, cap: 1048064)
Here is my code.
url := fmt.Sprintf("https://www.cryptocompare.com/api/data/coinlist/")
fmt.Println("Requesting data from " + url)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatal("NewRequest: ", err)
return
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Fatal("Do: ", err)
return
}
body, readErr := ioutil.ReadAll(resp.Body)
I want to be able to grab everything inside the Data key from the JSON and then map that to a struct. Can anyone see what I am doing wrong?
Below is an example of what I see in my browser when I hit the endpoint.
{
"Response": "Success",
"Message": "Coin list succesfully returned! This api is moving to https://min-api.cryptocompare.com/data/all/coinlist, please change the path.",
"BaseImageUrl": "https://www.cryptocompare.com",
"BaseLinkUrl": "https://www.cryptocompare.com",
"DefaultWatchlist": {
"CoinIs": "1182,7605,5038,24854,3807,3808,202330,5324,5031,20131",
"Sponsored": ""
},
"Data": {
"42": {
"Id": "4321",
"Url": "/coins/42/overview",
"ImageUrl": "/media/12318415/42.png",
"Name": "42",
"Symbol": "42",
"CoinName": "42 Coin",
"FullName": "42 Coin (42)",
"Algorithm": "Scrypt",
"ProofType": "PoW/PoS",
"FullyPremined": "0",
"TotalCoinSupply": "42",
"PreMinedValue": "N/A",
"TotalCoinsFreeFloat": "N/A",
"SortOrder": "34",
"Sponsored": false
},