Home

Awesome

Mentioned in Awesome Go pre-commit

Introduction

This is a benchmark for the json packages. You are welcome to open an issue if you find anything wrong or out of date.

TL;DR

In conclusion, the github.com/json-iterator/go is your first choice, it provides you with lots of useful features, oo design and high performance.

How to run

go test -v -bench ./...

Example result

GOGC=off go test -bench=. -benchmem

The result may vary according to the different environment. Use the result only as a reference.

ns/opB/opallocs/op
10Fields_Iterator_Objectjsoniter-readObjCB-8145802281014414
10Fields_Iterator_Objectjsoniter-readObj-8136915681314414
10Fields_Iterator_Objectjsonparser-81357131908804
10Fields_Iterator_Objectjzon-readObj-8123900095514414
10Fields_Iterator_Objectjzon-readObjCB-8120459399114414
10Fields_Unmarshal_Interfacedjson-84406432576117427
10Fields_Unmarshal_Interfaceeasyjson-84224602894117427
10Fields_Unmarshal_Interfacejzon-84145442904119028
10Fields_Unmarshal_Interfacejzon-fast-84259502917119028
10Fields_Unmarshal_Interfaceujson-83378813494149438
10Fields_Unmarshal_Interfacejsoniter-compatible-83207203758135038
10Fields_Unmarshal_Interfacejsoniter-83471264216135038
10Fields_Unmarshal_Interfacejson-82292185532141436
10Fields_Unmarshal_Interfaceugorji-82129915608247836
10Fields_Unmarshal_StructWithTagjsoniter-8100000010281925
10Fields_Unmarshal_StructWithTagjsoniter-compatible-8122328210341925
10Fields_Unmarshal_StructWithTagjzon-8100000011061925
10Fields_Unmarshal_StructWithTagjzon-fast-8100000011321925
10Fields_Unmarshal_StructWithTagugorji-8476871270510887
10Fields_Unmarshal_StructWithTagjson-8274917434643214
10Fields_Unmarshal_StructWoTagjsoniter-compatible-8887858140625615
10Fields_Unmarshal_StructWoTagjsoniter-8872038145125615
10Fields_Unmarshal_StructWoTagjzon-869478216071925
10Fields_Unmarshal_StructWoTagjson-8242374487943214
10Fields_Validgjson-8299154740000
10Fields_Validjzon-8209969556700
10Fields_Validjsoniter-compatible-815838697366410
10Fields_Validjsoniter-816287807586410
10Fields_Validjson-81000000111400
20Fields_Unmarshal_Interfacejzon-fast-81874826285273253
20Fields_Unmarshal_Interfacejzon-81939006516273153
20Fields_Unmarshal_Interfacedjson-82385526606271652
20Fields_Unmarshal_Interfaceeasyjson-81942996974271652
20Fields_Unmarshal_Interfaceujson-81637807551334073
20Fields_Unmarshal_Interfacejsoniter-compatible-81508297872305173
20Fields_Unmarshal_Interfacejsoniter-81399628286305173
20Fields_Unmarshal_Interfacejson-812187510689300367
20Fields_Unmarshal_Interfaceugorji-811927010768401861
20Fields_Unmarshal_StructWithTagjzon-851267323453689
20Fields_Unmarshal_StructWithTagjzon-fast-849763624023689
20Fields_Unmarshal_StructWithTagugorji-8484503253210887
20Fields_Unmarshal_StructWithTagjsoniter-8420992278051229
20Fields_Unmarshal_StructWithTagjsoniter-compatible-8420163287751229
20Fields_Unmarshal_StructWithTagjson-8145645846664824
20Fields_Unmarshal_StructWoTagjsoniter-compatible-8425262272451229
20Fields_Unmarshal_StructWoTagjsoniter-8435942275851229
20Fields_Unmarshal_StructWoTagjzon-8251348490810579
20Fields_Unmarshal_StructWoTagjson-8116900975964824
20Fields_Validgjson-8148301177600
20Fields_Validjzon-81000000107000
20Fields_Validjsoniter-compatible-8813631137614420
20Fields_Validjsoniter-8772488141814420
20Fields_Validjson-8564940213800

TODO

Packages tested

feature list

repoversionunmarshal (interface)unmarshal (struct)iteratorvalid
encoding/json1.15.2xxx
github.com/json-iterator/go1.1.10xxxx
github.com/buger/jsonparser1.0.0x
github.com/a8m/djsonc02c5aex
github.com/mailru/easyjson0.7.6x<sup>(1)</sup>
github.com/mreiferson/go-ujsonc02629fx<sup>(2)</sup>
github.com/ugorji/go/codec1.1.10x<sup>(3)</sup>x<sup>(4)</sup>
github.com/tidwall/gjson<sup>(5)</sup>1.6.1<sup>(6)</sup>x
github.com/zerosnake0/jzon0.0.5xxxx

notes:

  1. easyjson use its own marshaler/unmarshaler, which is not tested
  2. ujson use ujson.numeric which is its internal type for numbers
  3. ugorji need to be configured in order to be compatible with standard library
  4. ugorji decode into structure:
    • can decode into a structure with tag
    • cannot decode into a structure without a tag unless all field names are as same as tag names
    • use its own marshaler/unmarshaler (codec.Selfer) interface to decode structure
  5. gjson deprecated its unmarshal methods from v1.4.0
  6. gjson only decode into structure fields with tag (<= v1.3.6)

The following packages are not tested

reporeason
github.com/Jeffail/gabsthe encoding/decoding uses encoding/json
github.com/bitly/go-simplejsonthe encoding/decoding uses encoding/json
github.com/antonholmquist/jasonthe encoding/decoding uses encoding/json
github.com/pquerna/ffjsonthe encoding/decoding uses encoding/json (if the custom interface is not provided)