Hey, Philipp here!
I'd like to tell you, that my platform Go Web Examples Courses just launched. Enjoy easy to follow video courses about web devlopment in Go. Make sure to check out the special offer I have for early supporters.
We'll see us over there! :)
Learn more


This example will show how to encode and decode JSON data using the encoding/json package.

// json.go
package main

import (

type User struct {
    Firstname string `json:"firstname"`
    Lastname  string `json:"lastname"`
    Age       int    `json:"age"`

func main() {
    http.HandleFunc("/decode", func(w http.ResponseWriter, r *http.Request) {
        var user User

        fmt.Fprintf(w, "%s %s is %d years old!", user.Firstname, user.Lastname, user.Age)

    http.HandleFunc("/encode", func(w http.ResponseWriter, r *http.Request) {
        peter := User{
            Firstname: "John",
            Lastname:  "Doe",
            Age:       25,


    http.ListenAndServe(":8080", nil)
$ go run json.go

$ curl -s -XPOST -d'{"firstname":"Elon","lastname":"Musk","age":48}' http://localhost:8080/decode
Elon Musk is 48 years old!

$ curl -s http://localhost:8080/encode