diff --git a/urbdic/go.mod b/urbdic/go.mod new file mode 100644 index 0000000..fbf546f --- /dev/null +++ b/urbdic/go.mod @@ -0,0 +1,3 @@ +module urbdic + +go 1.22.2 diff --git a/urbdic/main.go b/urbdic/main.go new file mode 100644 index 0000000..d1f60a9 --- /dev/null +++ b/urbdic/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "encoding/json" + "fmt" + "log" +) + +type people struct { + Example int `json:"number"` + personalDetails personalDetails +} + +type personalDetails struct { + Name string `json:"name"` +} + +func main() { + query := ` + { + "message": "success", + "people": [ + { + "name": "Jasmin Moghbeli", + "craft": "ISS" + }, + { + "name": "Andreas Mogensen", + "craft": "ISS" + }, + { + "name": "Satoshi Furukawa", + "craft": "ISS" + }, + { + "name": "Konstantin Borisov", + "craft": "ISS" + }, + { + "name": "Oleg Kononenko", + "craft": "ISS" + }, + { + "name": "Nikolai Chub", + "craft": "ISS" + }, + { + "name": "Loral O'Hara", + "craft": "ISS" + } + ], + "number": 7 +}` + textBytes := []byte(query) + urbDicRequest := people{} + err := json.Unmarshal(textBytes, &urbDicRequest) + if err != nil { + log.Fatalf("Error happened parsing json: %v\n", err) + } + + fmt.Println(urbDicRequest.personalDetails.Name) + +}