9951 explained code solutions for 126 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