Skip to content

Instantly share code, notes, and snippets.

Created February 13, 2013 07:50
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Printing structs; convert structs to JSON format easily.
// Printing structs.
package main
import (
type Arc struct {
Head string
Modifier string
func main() {
arc := Arc{"saw", "He"}
fmt.Printf("%v\n", arc)
fmt.Printf("%+v\n", arc)
fmt.Printf("%#v\n", arc)
// Convert structs to JSON.
data, err := json.Marshal(arc)
if err != nil {
fmt.Printf("%s\n", data)
Copy link

sarnobat commented May 3, 2021

Works without any extra effort (for private fields too).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment