func ExampleUnmarshal() {
var jsonBlob = []byte(`[
- {"Name": "Platypus", "Order": "Monotremata"},
- {"Name": "Quoll", "Order": "Dasyuromorphia"}
- ]`)
+ {"Name": "Platypus", "Order": "Monotremata"},
+ {"Name": "Quoll", "Order": "Dasyuromorphia"}
+]`)
type Animal struct {
Name string
Order string
// This example uses a Decoder to decode a stream of distinct JSON values.
func ExampleDecoder() {
const jsonStream = `
- {"Name": "Ed", "Text": "Knock knock."}
- {"Name": "Sam", "Text": "Who's there?"}
- {"Name": "Ed", "Text": "Go fmt."}
- {"Name": "Sam", "Text": "Go fmt who?"}
- {"Name": "Ed", "Text": "Go fmt yourself!"}
- `
+ {"Name": "Ed", "Text": "Knock knock."}
+ {"Name": "Sam", "Text": "Who's there?"}
+ {"Name": "Ed", "Text": "Go fmt."}
+ {"Name": "Sam", "Text": "Go fmt who?"}
+ {"Name": "Ed", "Text": "Go fmt yourself!"}
+`
type Message struct {
Name, Text string
}
// This example uses a Decoder to decode a stream of distinct JSON values.
func ExampleDecoder_Token() {
const jsonStream = `
- {"Message": "Hello", "Array": [1, 2, 3], "Null": null, "Number": 1.234}
- `
+ {"Message": "Hello", "Array": [1, 2, 3], "Null": null, "Number": 1.234}
+`
dec := json.NewDecoder(strings.NewReader(jsonStream))
for {
t, err := dec.Token()
}
var j = []byte(`[
- {"Space": "YCbCr", "Point": {"Y": 255, "Cb": 0, "Cr": -10}},
- {"Space": "RGB", "Point": {"R": 98, "G": 218, "B": 255}}
- ]`)
+ {"Space": "YCbCr", "Point": {"Y": 255, "Cb": 0, "Cr": -10}},
+ {"Space": "RGB", "Point": {"R": 98, "G": 218, "B": 255}}
+]`)
var colors []Color
err := json.Unmarshal(j, &colors)
if err != nil {