Fast JSON encoder/decoder compatible with encoding/json for Go
Go to file
Masaaki Goshima ad8e97ff51 Update README.md 2020-05-08 20:21:20 +09:00
.github/workflows Create go.yml 2020-04-26 12:11:35 +09:00
benchmarks Remove easyjson from benchmark 2020-05-08 20:20:50 +09:00
LICENSE Initial commit 2020-04-19 18:32:37 +09:00
README.md Update README.md 2020-05-08 20:21:20 +09:00
decode.go Support interface{} type for decoding 2020-05-08 15:13:30 +09:00
decode_array.go Remove context for decoding 2020-05-07 02:37:29 +09:00
decode_bool.go Remove context for decoding 2020-05-07 02:37:29 +09:00
decode_context.go Improve performance skipWhiteSpace 2020-05-07 13:44:41 +09:00
decode_float.go Remove context for decoding 2020-05-07 02:37:29 +09:00
decode_int.go Fix decoder for int and string type 2020-05-07 14:21:29 +09:00
decode_interface.go Support interface{} type for decoding 2020-05-08 15:13:30 +09:00
decode_map.go Remove context for decoding 2020-05-07 02:37:29 +09:00
decode_ptr.go Remove context for decoding 2020-05-07 02:37:29 +09:00
decode_slice.go Reuse slice instance for decoding 2020-05-07 21:30:36 +09:00
decode_string.go Fix decoder for int and string type 2020-05-07 14:21:29 +09:00
decode_struct.go Refactor skipValue 2020-05-07 20:02:55 +09:00
decode_test.go Support interface{} type for decoding 2020-05-08 15:13:30 +09:00
decode_uint.go Remove context for decoding 2020-05-07 02:37:29 +09:00
encode.go Support MarshalJSON/MarshalText 2020-05-04 18:39:17 +09:00
encode_compile.go Support MarshalJSON/MarshalText 2020-05-04 18:39:17 +09:00
encode_map112.go Fix build 2020-04-26 12:49:54 +09:00
encode_map113.go Fix build 2020-04-26 12:49:54 +09:00
encode_opcode.go Support MarshalJSON/MarshalText 2020-05-04 18:39:17 +09:00
encode_string.go Support SetEscapeHTML 2020-05-03 17:41:33 +09:00
encode_test.go Support MarshalJSON/MarshalText 2020-05-04 18:39:17 +09:00
encode_vm.go Support MarshalJSON/MarshalText 2020-05-04 18:39:17 +09:00
error.go Support encoding for interface{} type 2020-04-28 18:25:51 +09:00
go.mod Fix benchmark 2020-04-26 12:03:17 +09:00
go.sum Fix benchmark 2020-04-26 12:03:17 +09:00
helper_test.go Fix helper of testing 2020-04-24 20:48:15 +09:00
json.go Append NUL character to end of buffer 2020-05-07 13:57:17 +09:00
rtype.go Add UnmarshalNoEscape 2020-04-24 21:57:11 +09:00

README.md

go-json

Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Status

WIP

API

  • Compact
  • HTMLEscape
  • Indent
  • Marshal
  • MarshalIndent
  • Unmarshal
  • Valid
  • NewDecoder
  • (*Decoder).Buffered
  • (*Decoder).Decode
  • (*Decoder).DisallowUnknownFields
  • (*Decoder).InputOffset
  • (*Decoder).More
  • (*Decoder).Token
  • (*Decoder).UseNumber
  • Delim
  • (Delim).String
  • NewEncoder
  • (*Encoder).Encode
  • (*Encoder).SetEscapeHTML
  • (*Encoder).SetIndent

Type

Encoder

  • int, int8, int16, int32, int64
  • uint, uint8, uint16, uint32, uint64
  • float32, float64
  • string
  • struct
  • array
  • slice
  • map
  • interface{}
  • MarshalJSON
  • MarshalText

Decoder

  • int, int8, int16, int32, int64
  • uint, uint8, uint16, uint32, uint64
  • float32, float64
  • string
  • struct
  • array
  • slice
  • map

Benchmarks

$ cd benchmarks
$ go test -bench .

Environment

goos: darwin
goarch: amd64

Decode

SmallStruct

Benchmark_Decode_SmallStruct_EncodingJson-12             1000000              1725 ns/op             280 B/op          3 allocs/op
Benchmark_Decode_SmallStruct_JsonIter-12                 1000000              1282 ns/op             316 B/op         12 allocs/op
Benchmark_Decode_SmallStruct_GoJay-12                    3000000               553 ns/op             256 B/op          2 allocs/op
Benchmark_Decode_SmallStruct_GoJayUnsafe-12              3000000               509 ns/op             112 B/op          1 allocs/op
Benchmark_Decode_SmallStruct_GoJson-12                   3000000               465 ns/op             256 B/op          2 allocs/op
Benchmark_Decode_SmallStruct_GoJsonNoEscape-12           3000000               407 ns/op             144 B/op          1 allocs/op

MediumStruct

Benchmark_Decode_MediumStruct_EncodingJson-12             100000             20688 ns/op             384 B/op         10 allocs/op
Benchmark_Decode_MediumStruct_JsonIter-12                 200000             10513 ns/op            2985 B/op         81 allocs/op
Benchmark_Decode_MediumStruct_GoJay-12                    500000              3400 ns/op            2449 B/op          8 allocs/op
Benchmark_Decode_MediumStruct_GoJayUnsafe-12              500000              3095 ns/op             144 B/op          7 allocs/op
Benchmark_Decode_MediumStruct_GoJson-12                   500000              2662 ns/op            2457 B/op          9 allocs/op
Benchmark_Decode_MediumStruct_GoJsonNoEscape-12           500000              2614 ns/op            2425 B/op          8 allocs/op

LargeStruct

Benchmark_Decode_LargeStruct_EncodingJson-12                5000            276637 ns/op             312 B/op          6 allocs/op
Benchmark_Decode_LargeStruct_JsonIter-12                   10000            158992 ns/op           41738 B/op       1137 allocs/op
Benchmark_Decode_LargeStruct_GoJay-12                      50000             36340 ns/op           31244 B/op         77 allocs/op
Benchmark_Decode_LargeStruct_GoJayUnsafe-12                50000             34337 ns/op            2561 B/op         76 allocs/op
Benchmark_Decode_LargeStruct_GoJson-12                     50000             39183 ns/op           30755 B/op         67 allocs/op
Benchmark_Decode_LargeStruct_GoJsonNoEscape-12             50000             38809 ns/op           30723 B/op         66 allocs/op

Encode

SmallStruct

Benchmark_Encode_SmallStruct_EncodingJson-12             1000000              1696 ns/op            1048 B/op          8 allocs/op
Benchmark_Encode_SmallStruct_JsonIter-12                 2000000               755 ns/op             984 B/op          7 allocs/op
Benchmark_Encode_SmallStruct_GoJay-12                    3000000               417 ns/op             624 B/op          2 allocs/op
Benchmark_Encode_SmallStruct_GoJson-12                   5000000               323 ns/op             144 B/op          1 allocs/op

MediumStruct

Benchmark_Encode_MediumStruct_EncodingJson-12             300000              3885 ns/op            1712 B/op         24 allocs/op
Benchmark_Encode_MediumStruct_JsonIter-12                1000000              1420 ns/op            1536 B/op         20 allocs/op
Benchmark_Encode_MediumStruct_GoJay-12                   1000000              1044 ns/op             824 B/op         15 allocs/op
Benchmark_Encode_MediumStruct_GoJson-12                  3000000               585 ns/op             320 B/op          1 allocs/op

LargeStruct

Benchmark_Encode_LargeStruct_EncodingJson-12               30000             53239 ns/op           20393 B/op        331 allocs/op
Benchmark_Encode_LargeStruct_JsonIter-12                  100000             21627 ns/op           20278 B/op        328 allocs/op
Benchmark_Encode_LargeStruct_GoJay-12                     100000             22256 ns/op           28048 B/op        323 allocs/op
Benchmark_Encode_LargeStruct_GoJson-12                    100000             17927 ns/op           14683 B/op        319 allocs/op

License

MIT