GoJay - Highly performant JSON encoder/decoder (currently the fastest)

Just released version 0.9.0 of a highly performant JSON encoder/decoder (currently the fastest).

It has a simple API and relies on simple interfaces to decode/encode structs, arrays, slices and even channels. It also has a powerful stream decoding feature.

It relies on a different approach than most encoder decoder, feedbacks from the community would be very welcome.

Feedbacks, reviews and contributions are welcome.

1 Like

Hey this looks really very interesting!

What was your motivation for the project and the design choices behind it? I’ve looked at quite a few go JSON parsers and haven’t seen one similar to this before.

Hi Mike, thank you for your answer.

Idea came while looking at other json packages. It was either a lot of reflection or some ugly static code generation. Nothing with simple interfaces to implement. So I felt like I could do something very performant if I relied on zero reflection and still being readable and fairly easy to use.

In terms of design, It was my first try at a JSON encoder/decoder, but I worked on interpreters and text parsers before.
For decoding, idea was to go for a sort of JIT decoding, which allows to use an io.Reader in the most efficient way, and also decoding only what we need. And while developing it, I realised my design had a nice potential to use channels for decoding, which I tried and added.
For encoding, it’s a similar take, using a string builder and zero reflection. The encoder is in fact quite simple and borrows from Go 1.10 strings.Builder to build byte buffer. I believe encoder can be improved (in a larger scale than the decoder) and will continue working on it.

Interesting! Thanks for the detailed response. Maybe you can add this to the README? ie a section on background/motivation/design choices/tradeoffs/etc?

Really like the streaming-JSON support I think that’s missing in other go JSON libraries.

I’ve been meaning to look into the new 1.10 strings.Builder - I’ll have to take some time and look into your implementation as well.

On code generation… one thing I thought when I looked through your library is that I could use it for code generation… ie I could generate code for a whole bunch of types (eg from a .proto file) to have them implement the right GoJay interfaces. Writing all the GoJay interfaces for more than one or two structs seems like a lot to write so I thought it would be a good fit for code generation. Perhaps down the line you could add an example of this to the repo and see if gets any interest?

How close do you think you it is to production use? Version 0.9 sounds close to 1.0 haha but unfortunately that’s not really how version numbers!

I will follow your advice and add it to the README.

Agree for the streaming part, I already have a couple of ideas on other open source packages to create based on this feature. Will add a streaming encoding feature as well.

You’re right, I’m not against code generation at all. What I meant is more some unreadable(or hardly readable) generated code, like EasyJson or ffjson, GoJay offers a simple API yet very efficient. We will probably write a generator to generate interface implementations for structures, slices and so on(shouldn’t be too hard as interfaces are small), not sure yet if it will be part of v1.0.

It should be usable soon in production. We plan for a version 1.0 in two weeks (May 11). I will update this thread and/or post a new one when it is ready :slight_smile:

Hey, giving some news here. GoJay has move pretty well, it is currently in version 0.10.6 targetting 1.0.0 very soon. Still the fastest JSON decoder/encoder out there. I have also built a very fast JSON logger, using GoJay and it is fast and efficient!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.