go icon indicating copy to clipboard operation
go copied to clipboard

json-iterator/go is not 100% compatible drop-in replacement of encoding/json

Open choleraehyq opened this issue 7 years ago • 8 comments

Several functions missing. Like Compact/Indent/HTMLEscape/Decoder.Token etc.

choleraehyq avatar Jan 28 '18 03:01 choleraehyq

no one is asking for them

taowen avatar Jan 28 '18 04:01 taowen

HTML Escaping is supported through the following, I think:

func jsonIteratorMarshalAddNewLineNoEscapeHTML(v interface{}) ([]byte, error) {
	buffer := &bytes.Buffer{}
	encoder := jsonIterator.NewEncoder(buffer)
	encoder.SetEscapeHTML(false)
	err := encoder.Encode(v)
	return buffer.Bytes(), err
}

veqryn avatar Jul 23 '18 08:07 veqryn

The readme says "100% compatibility with standard lib". I think that if this line were removed, this issue could be resolved...

carbocation avatar Aug 06 '18 18:08 carbocation

#313 relates to this. jsoniter doesn't support the Umarshaler interface: https://golang.org/pkg/encoding/json/#Unmarshaler

shatil avatar Oct 20 '18 00:10 shatil

I agree that the README should be updated to convey which parts are not compatible with encoding/json and not say "100% compatible". There are a couple functions missing from the Decoder type:

        func (dec *Decoder) InputOffset() int64
        func (dec *Decoder) Token() (Token, error)

I had wanted to try out switching to json-iterator/go, but our code currently depends on these functions for one of our packages that does stream processing of documents and I was surprised to find them missing given the claim of drop-in compatibility.

jszwedko avatar Apr 13 '20 16:04 jszwedko

no one is asking for them

Any updates on this? I'm asking. 👋 I'm just hit this issue. 🙈

Dentrax avatar Apr 18 '23 15:04 Dentrax

Another issue: https://github.com/json-iterator/go/issues/657

damnever avatar May 05 '23 07:05 damnever