Skip to content

Instantly share code, notes, and snippets.

@irshadhasmat
Last active July 22, 2022 15:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save irshadhasmat/7932c83fe62b74a2fd138cb117b67c65 to your computer and use it in GitHub Desktop.
Save irshadhasmat/7932c83fe62b74a2fd138cb117b67c65 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
)
func main() {
//Simple Employee JSON object which we will parse
empJson := `{
"id" : 11,
"name" : "Irshad",
"department" : "IT",
"designation" : "Product Manager"
}`
// Declared an empty interface
var result map[string]interface{}
// Unmarshal or Decode the JSON to the interface.
json.Unmarshal([]byte(empJson), &result)
//Reading each value by its key
fmt.Println("Id :", result["id"],
"\nName :", result["name"],
"\nDepartment :", result["department"],
"\nDesignation :", result["designation"])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment