TinyJSON is a codegen for JSONMarshal & JSONUnmarshal methods. It uses go/ast
to parse structs in packages, so any code won't run inside repo.
It targets to support tinygo
and avoid interfaces and reflect calls to aim
the best speed and tiny size.
Lexer is built using ragel
, which produces pushdown automaton.
Theoretically it is the fastest possible lexer for json.
It is in alpha. Almost everything works. Interfaces not supported yet. Feel free to file issue.
go get github.com/tinyjson/tinyjson
go install github.com/tinyjson/tinyjson
add this comment somewhere in library
//go:generate tinyjson $GOFILE
and this before each structure you want to have JSONMarshal & JSONUnmarshal methods.
//tinyjson:json
Warning: the comment above is only visible inside batch structure declaration. (TODO: fix)
Then run go generate
in package dir.
The goal is to depend only on bytes, strconv
and tiny repo lexer
with errors, strconv
dependency.
"bytes"
"strconv"
"github.com/tinyjson/lexer"
All most everything is working. Interfaces not supported yet. Pointers could not work sometimes (e.g. pointers on pointers and so on).
- Add support for all kind of pointers.
- Add support for optional marshal and unmarshal methods building.
- Add sting constant optimisation for marshalers.
- Add optional support for interfaces.