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
- encoding/json Recap
- encoding/xml
- encoding/csv
- gob and Binary Encoding