Marshal signifies stringify. Unmarshal signifies parse.
Go in your project directory, open a terminal and type the following
go get github.com/ithirzty/quickson
Then, in your main.go
import the following
import(
"github.com/ithirzty/quickson"
)
go get -u github.com/ithirzty/quickson
- It is up to 3x as fast as the native one (encoding/json), generaly 2x faster.
- It is really easy to use.
- Converting a struct into JSON:
myConvertedJson := quickson.Marshal(MyInterface)
- Parsing JSON into a struct:
data := myStruct{}
quickson.Unmarshal(json, &data)
- Paring JSON into a map/slice/string/bool/int
data := quickson.Unmarshal(json, false)
- It is best you don't use this tool if you need to marshal complex interfaces, Quickson is not yet capable of converting big interfaces.
Here is how to use concurrency with quickson:
result := ""
c := make(chan string)
go func() {
c <- quickson.Marshal(MyInterface)
}()
result <- c
Follow the installation guide run the following code:
package main
import(
"fmt"
"github.com/ithirzty/quickson"
)
type testInterface struct {
TestField string //"This is a test."
TestPassed map[string]bool //"My test": true
}
func main() {
testVar := testInterface{"This is a test.", map[string]bool{"My test": true}}
fmt.Printf("This is our struct converted in JSON: %v", quickson.Marshal(testVar))
//should output {"TestField":"This is a test.","TestPassed":{"My test":true}}
}