github.com/micro/go-micro/v2@v2.9.1/util/qson/README.md (about) 1 # qson 2 3 This is copy from https://github.com/joncalhoun/qson 4 As author says he is not acrivelly maintains the repo and not plan to do that. 5 6 ## Usage 7 8 You can either turn a URL query param into a JSON byte array, or unmarshal that directly into a Go object. 9 10 Transforming the URL query param into a JSON byte array: 11 12 ```go 13 import "github.com/joncalhoun/qson" 14 15 func main() { 16 b, err := qson.ToJSON("bar%5Bone%5D%5Btwo%5D=2&bar[one][red]=112") 17 if err != nil { 18 panic(err) 19 } 20 fmt.Println(string(b)) 21 // Should output: {"bar":{"one":{"red":112,"two":2}}} 22 } 23 ``` 24 25 Or unmarshalling directly into a Go object using JSON struct tags: 26 27 ```go 28 import "github.com/joncalhoun/qson" 29 30 type unmarshalT struct { 31 A string `json:"a"` 32 B unmarshalB `json:"b"` 33 } 34 type unmarshalB struct { 35 C int `json:"c"` 36 } 37 38 func main() { 39 var out unmarshalT 40 query := "a=xyz&b[c]=456" 41 err := Unmarshal(&out, query) 42 if err != nil { 43 t.Error(err) 44 } 45 // out should equal 46 // unmarshalT{ 47 // A: "xyz", 48 // B: unmarshalB{ 49 // C: 456, 50 // }, 51 // } 52 } 53 ``` 54 55 To get a query string like in the two previous examples you can use the `RawQuery` field on the [net/url.URL](https://golang.org/pkg/net/url/#URL) type.