Forked from XI4222-Irshad/SIMPLE_JSON_OBJECT_PARSING.go
Created
September 1, 2020 12:18
-
-
Save vikasavnish/86af12a9498f468e5a292ddd9b790774 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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