DockerCLI/vendor/github.com/json-iterator/go
Sebastiaan van Stijn c189c4dbea
[20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility
full diff: 0ff49de124...024077e996

Fixes a nil-pointer exception on go 1.18;

```
=== FAIL: cli/context/kubernetes TestSaveLoadContexts (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x40fcbc]

goroutine 19 [running]:
testing.tRunner.func1.2({0xa7e080, 0x1073930})
	/usr/local/go/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1392 +0x39f
panic({0xa7e080, 0x1073930})
	/usr/local/go/src/runtime/panic.go:838 +0x207
reflect.mapiternext(0x40?)
	/usr/local/go/src/runtime/map.go:1378 +0x19
github.com/docker/cli/vendor/github.com/modern-go/reflect2.(*UnsafeMapIterator).UnsafeNext(0x8?)
	/go/src/github.com/docker/cli/vendor/github.com/modern-go/reflect2/unsafe_map.go:136 +0x32
github.com/docker/cli/vendor/github.com/json-iterator/go.(*sortKeysMapEncoder).Encode(0xc000478930, 0xc0000ca3a8, 0xc0000bae40)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_map.go:293 +0x335
github.com/docker/cli/vendor/github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc00046c898?, 0x95d787?, 0xc0000bae58?)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:327 +0x22
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc000482630, 0xa2790c?, 0xc0000bae40)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000482780, 0xb3a599?, 0xc0000bae40)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*placeholderEncoder).Encode(0xc00046ca10?, 0x95d787?, 0xc0000bae58?)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:327 +0x22
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0004829f0, 0xa0fd11?, 0xc0000bae40)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000482a50, 0x40aa15?, 0xc0000bae40)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*sliceEncoder).Encode(0xc00047e198, 0xc0003a83c8, 0xc0000bae40)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_slice.go:38 +0x2bb
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structFieldEncoder).Encode(0xc0004837a0, 0xa12e12?, 0xc0000bae40)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:110 +0x56
github.com/docker/cli/vendor/github.com/json-iterator/go.(*structEncoder).Encode(0xc000483890, 0x0?, 0xc0000bae40)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_struct_encoder.go:158 +0x652
github.com/docker/cli/vendor/github.com/json-iterator/go.(*OptionalEncoder).Encode(0xc0003b6be0?, 0x0?, 0x0?)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect_optional.go:74 +0xa4
github.com/docker/cli/vendor/github.com/json-iterator/go.(*onePtrEncoder).Encode(0xc000471e30, 0xc0003a8370, 0xc000460720?)
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:214 +0x82
github.com/docker/cli/vendor/github.com/json-iterator/go.(*Stream).WriteVal(0xc0000bae40, {0xabe4a0, 0xc0003a8370})
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/reflect.go:93 +0x158
github.com/docker/cli/vendor/github.com/json-iterator/go.(*frozenConfig).Marshal(0xc0003b6be0, {0xabe4a0, 0xc0003a8370})
	/go/src/github.com/docker/cli/vendor/github.com/json-iterator/go/config.go:299 +0xc9
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json.(*Serializer).Encode(0xc00043aee0?, {0xc375c0?, 0xc0003a8370?}, {0xc339e0, 0xc000460210})
	/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/json/json.go:310 +0x6d
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning.(*codec).Encode(0xc0000f8480, {0xc37570?, 0xc0000bacc0}, {0xc339e0, 0xc000460210})
	/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/serializer/versioning/versioning.go:231 +0x926
github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime.Encode({0x7f48b36ce5c0, 0xc0000f8480}, {0xc37570, 0xc0000bacc0})
	/go/src/github.com/docker/cli/vendor/k8s.io/apimachinery/pkg/runtime/codec.go:46 +0x64
github.com/docker/cli/vendor/k8s.io/client-go/tools/clientcmd.Write(...)
	/go/src/github.com/docker/cli/vendor/k8s.io/client-go/tools/clientcmd/loader.go:469
github.com/docker/cli/cli/context/kubernetes.TestSaveLoadContexts(0xc0004561a0?)
	/go/src/github.com/docker/cli/cli/context/kubernetes/endpoint_test.go:75 +0xf0a
testing.tRunner(0xc0004561a0, 0xb89ea0)
	/usr/local/go/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1486 +0x35f
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-08-19 16:12:25 +02:00
..
LICENSE Add support for kubernetes in docker cli 2017-12-26 11:22:32 +01:00
README.md [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
adapter.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
any.go bump json-iterator/go 1.1.6 2019-03-19 17:13:03 +01:00
any_array.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_bool.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_float.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_int32.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_int64.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_invalid.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_nil.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_number.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_object.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_str.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
any_uint32.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
any_uint64.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
config.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
go.mod [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
iter.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
iter_array.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
iter_float.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
iter_int.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
iter_object.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
iter_skip.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
iter_skip_sloppy.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
iter_skip_strict.go bump json-iterator/go 1.1.6 2019-03-19 17:13:03 +01:00
iter_str.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
jsoniter.go Add support for kubernetes in docker cli 2017-12-26 11:22:32 +01:00
pool.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
reflect.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
reflect_array.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
reflect_dynamic.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
reflect_extension.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
reflect_json_number.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
reflect_json_raw_message.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
reflect_map.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
reflect_marshaler.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
reflect_native.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
reflect_optional.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
reflect_slice.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
reflect_struct_decoder.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
reflect_struct_encoder.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
stream.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
stream_float.go [20.10] vendor: github.com/json-iterator/go v1.1.12 for Go 1.18 compatibility 2022-08-19 16:12:25 +02:00
stream_int.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00
stream_str.go Bump kubernetes dependencies to 1.11 2018-07-25 11:34:59 +02:00

README.md

Sourcegraph GoDoc Build Status codecov rcard License Gitter chat

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

Benchmark

benchmark

Source code: https://github.com/json-iterator/go-benchmark/blob/master/src/github.com/json-iterator/go-benchmark/benchmark_medium_payload_test.go

Raw Result (easyjson requires static code generation)

ns/op allocation bytes allocation times
std decode 35510 ns/op 1960 B/op 99 allocs/op
easyjson decode 8499 ns/op 160 B/op 4 allocs/op
jsoniter decode 5623 ns/op 160 B/op 3 allocs/op
std encode 2213 ns/op 712 B/op 5 allocs/op
easyjson encode 883 ns/op 576 B/op 3 allocs/op
jsoniter encode 837 ns/op 384 B/op 4 allocs/op

Always benchmark with your own workload. The result depends heavily on the data input.

Usage

100% compatibility with standard lib

Replace

import "encoding/json"
json.Marshal(&data)

with

import jsoniter "github.com/json-iterator/go"

var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Marshal(&data)

Replace

import "encoding/json"
json.Unmarshal(input, &data)

with

import jsoniter "github.com/json-iterator/go"

var json = jsoniter.ConfigCompatibleWithStandardLibrary
json.Unmarshal(input, &data)

More documentation

How to get

go get github.com/json-iterator/go

Contribution Welcomed !

Contributors

Report issue or pull request, or email taowen@gmail.com, or Gitter chat