2808 explained code solutions for 75 technologies


golangHow to convert map to JSON


package main
import ("encoding/json")

func main() {
  mp := make(map[string]string)

  mp["name"] = "Joe"
  mp["position"] = "president"
  
  str, _ := json.Marshal(mp)
  str = string(str)
}ctrl + c
package main

default package declaration

"encoding/json"

lib to work with JSON

json.Marshal

converts given argument to JSON

string(

convert given value to string