0Pricing
Go Academy · Lesson

encoding/json Recap

Marshal and unmarshal JSON.

JSON in Go

JSON is the most common data format for APIs. Go's standard encoding/json package converts between Go values and JSON text.

Marshal: Go to JSON

json.Marshal turns a Go value into a JSON byte slice. Convert it to a string to print.

package main

import (
	"encoding/json"
	"fmt"
)

func main() {
	data := map[string]int{"a": 1, "b": 2}
	b, _ := json.Marshal(data)
	fmt.Println(string(b))
}

All lessons in this course

  1. encoding/json Recap
  2. encoding/xml
  3. encoding/csv
  4. gob and Binary Encoding
← Back to Go Academy