https://github.com/ithirzty/quickson
A faster json marshaler/unmarshaler library for golang
https://github.com/ithirzty/quickson
faster go golang json marshaler marshalling parser
Last synced: 5 months ago
JSON representation
A faster json marshaler/unmarshaler library for golang
- Host: GitHub
- URL: https://github.com/ithirzty/quickson
- Owner: ithirzty
- License: apache-2.0
- Created: 2020-10-30T15:01:31.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-11-03T14:26:13.000Z (over 5 years ago)
- Last Synced: 2024-06-21T03:18:17.988Z (about 2 years ago)
- Topics: faster, go, golang, json, marshaler, marshalling, parser
- Language: Go
- Homepage:
- Size: 105 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Quickson: Fast JSON Marshaller/Unmarshaller for golang. [](https://github.com/ithirzty/quickson/blob/main/LICENSE)
##### What is a marshaller? Unmarshaller?
Marshal signifies stringify. Unmarshal signifies parse.
## Installing
Go in your project directory, open a terminal and type the following
```bash
go get github.com/ithirzty/quickson
```
Then, in your `main.go` import the following
```golang
import(
"github.com/ithirzty/quickson"
)
```
### How to update
```bash
go get -u github.com/ithirzty/quickson
```
## Why?
* It is up to 3x as fast as the native one (encoding/json), generaly 2x faster.
* It is really easy to use.
# How to use
* Converting a struct into JSON:
```golang
myConvertedJson := quickson.Marshal(MyInterface)
```
* Parsing JSON into a struct:
```golang
data := myStruct{}
quickson.Unmarshal(json, &data)
```
* Paring JSON into a map/slice/string/bool/int
```golang
data := quickson.Unmarshal(json, false)
```
## Cons
* 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.
## Less performance under load?
Here is how to use concurrency with quickson:
```golang
result := ""
c := make(chan string)
go func() {
c <- quickson.Marshal(MyInterface)
}()
result <- c
```
## How can I test it?
Follow the installation guide run the following code:
```golang
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}}
}
```