I'm parsing a JSON file with an unusual structure which looks like this:
{
"394885":
{
"record":
{
"student_name": "Daryl Jones",
"student_number": 123884,
"student_dob": "12/10/1982",
"student_email": "djones@school.ac.uk",
}
},
}
I've been working through some code demos, but I would like to put it all in to a struct, which I then plan to search through by the number string that's the object name I would guess?
I'm not strong on JSON or Go, and this is the code I've written so far:
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
type id struct {
recordid string
record []record
}
type record struct {
name string
number uint32
dob string
email string
}
func main() {
jsonFile, err := os.Open("/home/emyrw/development/go/src/json_processor/demo.json")
if err != nil {
fmt.Println(err)
} else {
var records id
byteValue, _ := ioutil.ReadAll(jsonFile)
json.Unmarshal(byteValue, &records)
fmt.Println(records)
fmt.Println("opened demo.json")
defer jsonFile.Close()
}
}
I'm not sure I've got it right, but would value any tips or advice anyone has to offer. I've been googling, but none of the samples I find quite fit my scenario.