• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..16-Jun-2021-

README.mdH A D16-Jun-20211.5 KiB5643

decode.goH A D16-Jun-202136.4 KiB1,3771,008

encode.goH A D16-Jun-202135.3 KiB1,318929

fold.goH A D16-Jun-20213.4 KiB144102

indent.goH A D16-Jun-20213.4 KiB142107

scanner.goH A D16-Jun-202115.1 KiB574412

stream.goH A D16-Jun-202112.5 KiB508356

tables.goH A D16-Jun-20214.2 KiB219198

tags.goH A D16-Jun-20211.1 KiB4529

README.md

1# jsonx
2
3It's modified version of [encoding/json](https://golang.org/pkg/encoding/json/)
4which enables extra map field (with `jsonx:"true"` tag) to catch all other fields not declared in the struct.
5
6`jsonx` is a code name for internal use
7and not related to [JSONx](https://tools.ietf.org/html/draft-rsalz-jsonx-00).
8
9Example ([Run on playgroud](https://play.golang.org/p/TZi0JeHYG69))
10```go
11package main
12
13import (
14	"encoding/json"
15	"fmt"
16
17	"github.com/yaegashi/msgraph.go/jsonx"
18)
19
20type Extra struct {
21	X     string
22	Y     int
23	Extra map[string]interface{} `json:"-" jsonx:"true"`
24}
25
26func main() {
27	var x1, x2 Extra
28	b := []byte(`{"X":"123","Y":123,"A":"123","B":123}`)
29	fmt.Printf("\nUnmarshal input: %s\n", string(b))
30	json.Unmarshal(b, &x1)
31	fmt.Printf(" json.Unmarshal: %#v\n", x1)
32	jsonx.Unmarshal(b, &x2)
33	fmt.Printf("jsonx.Unmarshal: %#v\n", x2)
34
35	x := Extra{X: "456", Y: 456, Extra: map[string]interface{}{"A": "456", "B": 456}}
36	fmt.Printf("\nMarshal input: %#v\n", x)
37	b1, _ := json.Marshal(x)
38	fmt.Printf(" json.Marshal: %s\n", string(b1))
39	b2, _ := jsonx.Marshal(x)
40	fmt.Printf("jsonx.Marshal: %s\n", string(b2))
41}
42```
43
44Result
45
46```text
47Unmarshal input: {"X":"123","Y":123,"A":"123","B":123}
48 json.Unmarshal: main.Extra{X:"123", Y:123, Extra:map[string]interface {}(nil)}
49jsonx.Unmarshal: main.Extra{X:"123", Y:123, Extra:map[string]interface {}{"A":"123", "B":123}}
50
51Marshal input: main.Extra{X:"456", Y:456, Extra:map[string]interface {}{"A":"456", "B":456}}
52 json.Marshal: {"X":"456","Y":456}
53jsonx.Marshal: {"X":"456","Y":456,"A":"456","B":456}
54```
55
56