◦ You need to create an intermediate decoder json.NewDecoder(r).Decode(v), but it doesn’t reject trailing junk (#36225) • Marshal, Unmarshal, and custom Marshaler and Unmarshaler do not accept options • Encoder or Decoder can accept options, but some options depend on bytes.Buffer instead of []byte or io.Writer
returned []byte • MarshalJSON and UnmarshalJSON forces a second parse • Lack of streaming ◦ Even though the Encoder.Encode and Decoder.Decode operate on an io.Writer or io.Reader, they buffer the entire JSON value in memory
8259) ◦ Invalid UTF-8 is allowed ◦ Duplicate object member names are allowed • The MarshalJSON and UnmarshalJSON methods cannot be called if the underlying value is not addressable • Case-insensitive unmarshaling • Inconsistent error values
▪ Syntactic functionality that processes JSON based on its grammar ▪ “encode” and “decode” ▪ A relatively light dependency tree ◦ json ▪ Semantic functionality that determines the meaning of JSON values as Go values and vice-versa ▪ “marshal” and “unmarshal” ▪ Depends on the reflect package
match the signature of the v1 functions • MarshalWriter and UnmarshalRead ◦ Accept io.Writer and io.Reader instead of []byte • MarshalEncode and UnmarshalDecode ◦ Accept *jsontext.Encoder and *jsontext.Decoder
is well thought out, not only performance, API flexibility, security safety, and RFC compliance, but also backward compatibility and migration flexibility • The idea of splitting syntactic functionality and semantic functionality into two packages, jsontext and json, would be a good idea • Nevertheless, many changes have been made, so you will have to migrate with each and every option, which will be somewhat nerve-wracking :(
to improve problems that v1 has, such as missing functionality, API deficiencies, and performance limitations • You can see the implementation https://github.com/go-json-experiment/json • Discussion is now open https://github.com/golang/go/discussions/63397
Go Source Code with Orchestrion” at mercari.go #24 on Nov 1 (tomorrow!) • “The Future of encoding/json” at Go Conference mini 2023 Winter IN KYOTO on Dec 2