From the course: Learning the Go Standard Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Encoding JSON - Go Tutorial
From the course: Learning the Go Standard Library
Encoding JSON
- [Instructor] JSON is a very common way of encoding and transmitting data via the internet. And in this example, we're going to see how to encode data within a Go Program into JSON. We'll also see to how to decode JSON back into native Go data structures in a separate video. So, let's open our code in our editor. And here in chapter 5, I'm going to open up JSONEncode. So, when we look at this file, we can see a few things. So first, I have a struct which represents some data about a person. And we're going to fill out this function named encodeExample that will serialize the data from that struct into JSON. So let's start by creating some actual data for the struct. So I'm going to uncomment this code right here. And this code creates an array of two separate person records along with some sample data. So to convert this structure to JSON I can use the JSON packages Marshal function. So let me begin by importing the modules…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.