typeAppstruct { Id string`json:"id"` Title string`json:"title"`}data := []byte(` { "id": "k34rAT4", "title": "My Awesome App" }`)var app Apperr := json.Unmarshal(data, &app)
Struct => Json
b, err := json.Marshal(m)
Simpler Parsing Into Struct
will need to be same as JSON keys and vals(not case sensitive)
typeTourstruct { Name, Price string}
Printing Byte Array
fmt.print("%s", byt)
Decoder
Grab json data from content using you struct
functoursFromJson(content string) []Tour { //content is array of JSON tours :=make([]Tour, 0, 20) decoder := json.NewDecoder(string.NewReader(content)) _, err := decoder.Token() //throw away that first '[' checkError(err)var tour Tourfor decoder.More() { //More asks if there is another data entity and if true returns true and moves decoder there err := decoder.Decoder(&tour)//parse JSON and only get those values in your struct leaving it in tourcheckError(err) tours =append(tours, tour) }return tours}