golang convert json string to map
jsonMap := make(map[string]interface{})
err := json.Unmarshal([]byte(jsonStr), &jsonMap)
golang convert json string to map
jsonMap := make(map[string]interface{})
err := json.Unmarshal([]byte(jsonStr), &jsonMap)
golang struct to json output
package main
import (
"encoding/json"
"fmt"
"log"
)
type employee1 struct {
Name string `json:"n"`
Age int `json:"a"`
salary int `json:"s"`
}
type employee2 struct {
Name string
Age int
salary int
}
func main() {
e1 := employee1{
Name: "John",
Age: 21,
salary: 1000,
}
j, err := json.Marshal(e1)
if err != nil {
log.Fatalf("Error occured during marshaling. Error: %s", err.Error())
}
fmt.Printf("employee1 JSON: %sn", string(j))
e2 := employee2{
Name: "John",
Age: 21,
salary: 1000,
}
j, err = json.Marshal(e2)
if err != nil {
log.Fatalf("Error occured during marshaling. Error: %s", err.Error())
}
fmt.Printf("nemployee2 JSON: %sn", string(j))
}
golang json to struct
type response2 struct {
Page int `json:"page"`
Fruits string `json:"fruits"`
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us