Skip to content

Instantly share code, notes, and snippets.

@XI4222-Irshad
Last active September 1, 2020 12:18
Show Gist options
  • Save XI4222-Irshad/76f2f20e4f9242962a5618701133675b to your computer and use it in GitHub Desktop.
Save XI4222-Irshad/76f2f20e4f9242962a5618701133675b to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
)
func main() {
//Simple Employee JSON which we will parse
empArray := `[
{
"id": 1,
"name": "Mr. Boss",
"department": "",
"designation": "Director"
},
{
"id": 11,
"name": "Irshad",
"department": "IT",
"designation": "Product Manager"
},
{
"id": 12,
"name": "Pankaj",
"department": "IT",
"designation": "Team Lead"
}
]`
// Declared an empty interface of type Array
var results []map[string]interface{}
// Unmarshal or Decode the JSON to the interface.
json.Unmarshal([]byte(empArray), &results)
for key, result := range results {
fmt.Println("Reading Value for Key :", key)
//Reading each value by its key
fmt.Println("Id :", result["id"],
"- Name :", result["name"],
"- Department :", result["department"],
"- Designation :", result["designation"])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment