quickson

package module
v0.0.0-...-4b75602 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(x interface{}) string

Marshal is used to convert a struct/interface into JSON. It outputs a string Usage: jsonText := quickson.Marshal(myInterface) Where the interface can be anything like a struct, map, int, slice.... The result will be inline JSON with no indentation

func Unmarshal

func Unmarshal(t string, i interface{}) interface{}

Unmarshal has two purposes: -It can parse JSON to a struct with a pointer Unmarshal(json, &myinterface) -Extract data to a map/slice/string/bool/int myMap := Unmarshal(json, false)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL