Skip to content

A faster json marshaler/unmarshaler library for golang

License

Notifications You must be signed in to change notification settings

ithirzty/quickson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Quickson: Fast JSON Marshaller/Unmarshaller for golang. 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

go get github.com/ithirzty/quickson

Then, in your main.go import the following

import(
	"github.com/ithirzty/quickson"
)

How to update

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:
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)

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:

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:

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}}
}

Releases

No releases published

Packages

 
 
 

Languages