High performance parsing and manipulation of JSON documents for Go.
Inspired by github.com/valyala/fastjson
- Does not try to be a 'drop-in' replacement for
encoding/json
- Deserialize arbitrary JSON input to a DOM tree
- Manipulate DOM tree
- Path lookups
- Lazy unescape and number conversions for faster parsing
- Reserialze to JSON data
- Iterate over tree
- Documents can be reused to avoid allocations
- Fast, fast, fast
- [WIP] Support for
reflect
based struct Marshal/Unmarshal viagithub.com/alxarch/njson/unjson
package - [WIP] CLI tool for Marshal/Unmarshal generated code via
github.com/alxarch/njson/cmd/njson
package
d := njson.Document{}
root, _, _ := d.Parse(`{"answer":42, "foo": {"bar": "baz"}}`)
answer, _ := root.Get("answer").ToInt()
fmt.Println(answer)
n := root.Lookup("foo", "bar")
bar := n.Unescaped()
fmt.Println(bar)
n.SetString("Hello, 世界")
data := make([]byte, 64)
data, _ = root.AppendJSON(data[:0])
fmt.Println(string(data))
// Output:
// 42
// baz
// {"answer":42,"foo":{"bar":"Hello, 世界"}}