Skip to content

Instantly share code, notes, and snippets.

@ejcx
Created November 4, 2014 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejcx/1ff9848b2f8fc42f21c3 to your computer and use it in GitHub Desktop.
Save ejcx/1ff9848b2f8fc42f21c3 to your computer and use it in GitHub Desktop.
golang print json
package main
import (
"fmt"
"os"
"encoding/json"
)
type Foobar struct {
A_int int
A_str string
}
func main() {
f := &Foobar {
A_int: 123,
A_str: "beep boop",
}
output, err := json.Marshal(f)
if err != nil {
fmt.Println("Couldn't marshall f")
} else {
os.Stdout.Write(output)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment