Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Encoding & Decoding – JSON, | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 36 of 60

·Go

Encoding & Decoding – JSON, XML, and Gob

20 minutes

Course progress60%

JSON (most common)

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

type Person struct {
    Name string `json:"name"`
    Age  int    `json:"age"`
}

p := Person{"Bob", }
bytes, _ := json.Marshal(p)
fmt.Println((bytes)) 
42
string
// {"name":"Bob","age":42}

XML

type Item struct {
    XMLName xml.Name `xml:"item"`
    ID      int      `xml:"id,attr"`
    Title   string   `xml:"title"`
}

Gob (binary Go encoder)

var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
enc.Encode(p) // p must be exported fields

Info

When dealing with external APIs, prefer json.Decoder with DisallowUnknownFields() to surface unexpected payloads.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonTime Package – Parsing, Formatting, and TimersContinue to lesson 37Authentication – JWT and MiddlewareBack to Go Programming Bootcamp curriculum