aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/json.go
blob: 598f8cbe3398340354681efdd72264f706f867ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package main

import (
	"encoding/json"
)

func main() {
	println("int:", encode(3))
	println("float64:", encode(3.14))
	println("string:", encode("foo"))
	println("slice of strings:", encode([]string{"foo", "bar"}))
}

func encode(itf interface{}) string {
	buf, err := json.Marshal(itf)
	if err != nil {
		panic("failed to JSON encode: " + err.Error())
	}
	return string(buf)
}