File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ j := jsn.O{
30
30
" do" : jsn.A {
31
31
" go" , " mod" , " tidy" ,
32
32
},
33
+ " x" : jsn.N (" 123456.00000000000000000000000000000000000000001" ),
33
34
}
34
35
35
36
raw , _ := json.MarshalIndent (j, " " , " " )
@@ -42,7 +43,8 @@ fmt.Printf("%s\n", raw)
42
43
// "mod",
43
44
// "tidy"
44
45
// ],
45
- // "hello": "world"
46
+ // "hello": "world",
47
+ // "x": 123456.00000000000000000000000000000000000000001
46
48
// }
47
49
```
48
50
Original file line number Diff line number Diff line change @@ -7,12 +7,13 @@ import (
7
7
"github.com/cristalhq/jsn"
8
8
)
9
9
10
- func ExampleUsage () {
10
+ func Example () {
11
11
j := jsn.O {
12
12
"hello" : "world" ,
13
13
"do" : jsn.A {
14
14
"go" , "mod" , "tidy" ,
15
15
},
16
+ "x" : jsn .N ("123456.00000000000000000000000000000000000000001" ),
16
17
}
17
18
18
19
raw , _ := json .MarshalIndent (j , "" , " " )
@@ -25,6 +26,25 @@ func ExampleUsage() {
25
26
// "mod",
26
27
// "tidy"
27
28
// ],
28
- // "hello": "world"
29
+ // "hello": "world",
30
+ // "x": 123456.00000000000000000000000000000000000000001
31
+ //}
32
+ }
33
+
34
+ func ExampleNumber () {
35
+ j := jsn.O {
36
+ "x" : 123456.00000000000000000000000000000000000000001 ,
37
+ "y" : jsn .N ("123456.00000000000000000000000000000000000000001" ),
38
+ "z" : "123456.00000000000000000000000000000000000000001" ,
39
+ }
40
+
41
+ raw , _ := json .MarshalIndent (j , "" , " " )
42
+ fmt .Printf ("%s\n " , raw )
43
+
44
+ // Output:
45
+ //{
46
+ // "x": 123456,
47
+ // "y": 123456.00000000000000000000000000000000000000001,
48
+ // "z": "123456.00000000000000000000000000000000000000001"
29
49
//}
30
50
}
Original file line number Diff line number Diff line change @@ -5,3 +5,10 @@ type A = []any
5
5
6
6
// O represents JSON object.
7
7
type O = map [string ]any
8
+
9
+ // N represents JSON number.
10
+ type N string
11
+
12
+ func (n N ) MarshalJSON () ([]byte , error ) {
13
+ return []byte (n ), nil
14
+ }
You can’t perform that action at this time.
0 commit comments