Wrong type of keys!

Report a typo

Emma has created a Go program that serializes the medals map into the medalsJSON variable, however when she tried to print the serialized medalsJSON she got the following error:

json: unsupported type: map[interface {}]string

Can you help her find and fix the error within her code so that she can properly serialize the medals map?

Tip: Remember what is the only data type that JSON supports for map keys!

Write a program in Go
package main

import (
"encoding/json"
"fmt"
"log"
)

func main() {
// HINT: The error is within the 'medals' map declaration:
medals := map[interface{}]string{
"first": "Gold",
"second": "Silver",
"third": "Bronze",
}

medalsJSON, err := json.Marshal(medals)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(medalsJSON))
}
___

Create a free account to access the full topic