...
1 package jwriter
2
3 import (
4 "encoding/json"
5 "fmt"
6 )
7
8 func ExampleArrayState_Null() {
9 w := NewWriter()
10 arr := w.Array()
11 arr.Null()
12 arr.Null()
13 arr.End()
14
15 fmt.Println(string(w.Bytes()))
16
17 }
18
19 func ExampleArrayState_Bool() {
20 w := NewWriter()
21 arr := w.Array()
22 arr.Bool(true)
23 arr.Bool(false)
24 arr.End()
25
26 fmt.Println(string(w.Bytes()))
27
28 }
29
30 func ExampleArrayState_Int() {
31 w := NewWriter()
32 arr := w.Array()
33 arr.Int(123)
34 arr.Int(456)
35 arr.End()
36
37 fmt.Println(string(w.Bytes()))
38
39 }
40
41 func ExampleArrayState_Float64() {
42 w := NewWriter()
43 arr := w.Array()
44 arr.Float64(1234.5)
45 arr.Float64(6)
46 arr.End()
47
48 fmt.Println(string(w.Bytes()))
49
50 }
51
52 func ExampleArrayState_String() {
53 w := NewWriter()
54 arr := w.Array()
55 arr.String(`string says "hello"`)
56 arr.String("ok")
57 arr.End()
58 fmt.Println(string(w.Bytes()))
59
60 }
61
62 func ExampleArrayState_Array() {
63 w := NewWriter()
64 arr := w.Array()
65 arr.Int(1)
66 subArr := arr.Array()
67 subArr.Int(2)
68 subArr.Int(3)
69 subArr.End()
70 arr.Int(4)
71 arr.End()
72
73 fmt.Println(string(w.Bytes()))
74
75 }
76
77 func ExampleArrayState_Object() {
78 w := NewWriter()
79 arr := w.Array()
80 obj1 := arr.Object()
81 obj1.Name("value").Int(1)
82 obj1.End()
83 obj2 := arr.Object()
84 obj2.Name("value").Int(2)
85 obj2.End()
86 arr.End()
87
88 fmt.Println(string(w.Bytes()))
89
90 }
91
92 func ExampleArrayState_Raw() {
93 data := json.RawMessage(`{"value":1}`)
94 w := NewWriter()
95 arr := w.Array()
96 arr.Raw(data)
97 arr.End()
98
99 fmt.Println(string(w.Bytes()))
100
101 }
102
View as plain text