A map is a dynamic structure of key-value pairs. Like a hash or dictionary in other languages.

  • JSON cheatsheet for converting a JSON string to a map.

Syntax

Declare:

map[KEY_TYPE]VALUE_TYPE

Examples

Declare empty.

var a map[string]int

var b map[string]interface{}

Declare with contents:

x := map[string]int{ "foo": 10, "bar": 123 }
isLegume := map[string]bool{
    "peanut":    true,
    "dachshund": false,
}

Update:

b["bazz"] = 999