Skip to content

A high-performance 100% compatible drop-in replacement of "encoding/json"

License

Notifications You must be signed in to change notification settings

go-shafaq/jsoniter

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsoniter

forked from github.com/json-iterator/go

Added future:

casting names automatically if needed

no more tagging every single field to specify its name

Basic Usage

Installation

go get github.com/go-shafaq/jsoniter

Code

Here is a minimal example.

package main

import (
	"fmt"
	"github.com/go-shafaq/defcase"
	jsoniter "github.com/go-shafaq/jsoniter"
)

func main() {
	// Get Public Default case
	dcase := defcase.Get()
	// Set a case for "json" tag and specific package
	// "*" means any package
	dcase.SetCase("json", "*", defcase.Snak_case)
	
	// Set a Default_Case to library
	jsoniter.SetDefCase(dcase)
	// Marshal a struct (which has no tags)
	var json = jsoniter.ConfigCompatibleWithStandardLibrary
	bytes, _ := json.Marshal(Item{Id: 3, Name: "laptop", CategoryId: 11})

	fmt.Println(string(bytes))
}

type Item struct {
	Id         int `casting:"no more tags"`
	Name       string
	CategoryId int
}

Terminal

Printed result

{"id":3,"name":"laptop","category_id":11}

Pretty json

{
  "id": 3,
  "name": "laptop",
  "category_id": 11
}

About

A high-performance 100% compatible drop-in replacement of "encoding/json"

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Go 99.9%
  • Shell 0.1%