Created
November 4, 2014 00:05
-
-
Save ejcx/1ff9848b2f8fc42f21c3 to your computer and use it in GitHub Desktop.
golang print json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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