jzon alternatives and similar packages
Based on the "JSON" category.
Alternatively, view jzon alternatives based on common mentions on social networks and blogs.
-
jsonparser
One of the fastest alternative JSON parser for Go that does not require schema -
fastjson
Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection -
marshmallow
Marshmallow provides a flexible and performant JSON unmarshalling in Go. It specializes in dealing with unstructured struct - when some fields are known and some aren't, with zero performance overhead nor extra coding needed. -
jsondiff
Compute the diff between two JSON documents as a series of RFC6902 (JSON Patch) operations -
JSON-to-Proto
convert JSON to Protocol Buffers online in your browser instantly -
ujson
µjson - A fast and minimal JSON parser and transformer that works on unstructured JSON -
mapslice-json
Go MapSlice for ordered marshal/ unmarshal of maps in JSON -
ask
A Go package that provides a simple way of accessing nested properties in maps and slices. -
Better Parsing of Unstructured JSON in Go
An error propagating JSON parsing library for Go -
epoch
Contains primitives for marshaling/unmarshaling Unix timestamp/epoch to/from built-in time.Time type in JSON -
go-jsonerror
Small package which wraps error responses to follow jsonapi.org -
go-parameters
:blue_book: Easily parse incoming parameters and values from an HTTP request -
jsonhandlers
JSON library to expose simple handlers that lets you easily read and write json from various sources.
Learn any GitHub repo in 59 seconds
Do you think we are missing an alternative of jzon or a related project?
Popular Comparisons
README
jzon
Why another jsoniter?
The code I write here is very similar to github.com/json-iterator/go, so you may ask why reinvent the wheel.
For sure that I benefit a lot from the jsoniter
library, but i found some inconvenience for me to use it
in some condition, for example:
- the iterator methods ReadString accepts null, there is no method which accepts exactly string. I have to do some extra check before calling.
- some behavior is not compatible with the standard library.
- I want a chained streamer
On the other hand, I also want to learn how the jsoniter
works, so there is this repo.
What's different from jsoniter?
Here are some of the differences:
- the iterator methods accept the exact type, for example ReadString accepts only string, not null
- the behavior is almost the same as the standard library (when an error returns, the behavior may differ from the standard library)
- the error of the iterator is returned instead of being saved inside iterator
- the decoder/encoder interface has additional options, like struct tag options
Some features of jsoniter
are not implemented, and may be not implemented in the future neither.
I choose only the ones I need to implement.
Compatibility with standard library
I tried implemented a version which is completely compatible with the standard library:
https://github.com/zerosnake0/jzon/tree/reflect
The benchmark shows that it's much faster than the standard library. However it is still much slower than the current version, which cannot be exactly the same as standard library (at least in my POV).
The major incompatibility is about the two following interfaces:
json.Marshaler
encoding.TextMarshaler
The method on pointer receiver may be called with an unaddressable value, for example:
type field struct {}
func (*field) MarshalJSON() ([]byte, error)
type st struct {
F field
}
json.Marshal(st{}) // will not call field.MarshalJSON
jzon.Marshal(st{}) // will call field.MarshalJSON
So the user should be care when marshaling a value when method on pointer receiver is involved
You can check the tests for more detailed info about the difference
How to use
Standard library like
import "github.com/zerosnake0/jzon"
// Unmarshal
err := jzon.Unmarshal(b, &data)
// Marshal
b, err := jzon.Marshal(&data)
// Decoder
dec := jzon.NewDecoder(reader)
defer dec.Release()
err := dec.Decode(&data)
// Encoder
enc := jzon.NewEncoder(writer)
defer enc.Release()
err := enc.Encode(&data)
Iterator
iter := jzon.NewIterator()
defer iter.Release()
iter.Reset(b)
jzon.ReadVal(&data)
Streamer
var w io.Writer
streamer := jzon.NewStreamer()
defer streamer.Release()
streamer.Reset(w)
streamer.Value(&data)
streamer.Flush()
Custom Decoder
see decoder_test.go
type testIntDecoder struct{}
func (*testIntDecoder) Decode(ptr unsafe.Pointer, it *Iterator, opts *DecOpts) error {
...
}
dec := NewDecoderConfig(&DecoderOption{
ValDecoders: map[reflect.Type]ValDecoder{
reflect.TypeOf(int(0)): (*testIntDecoder)(nil),
},
CaseSensitive: true,
})
// standard library like
err := dec.Unmarshal(b, &data)
// iterator
iter := dec.NewIterator()
defer iter.Release()
Custom Encoder
see encoder_test.go
type testIntEncoder struct{}
func (*testIntEncoder) IsEmpty(ptr unsafe.Pointer) bool {
...
}
func (*testIntEncoder) Encode(ptr unsafe.Pointer, s *Streamer, opts *EncOpts) {
...
}
enc := NewEncoderConfig(&EncoderOption{
ValEncoders: map[reflect.Type]ValEncoder{
reflect.TypeOf(int(0)): (*testIntEncoder)(nil),
},
})
// standard library like
b, err := enc.Marshal(&data)
// streamer
streamer := enc.NewStreamer()
defer streamer.Release()