Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/romshark/jscan
High performance JSON iterator & validator for Go
https://github.com/romshark/jscan
go golang high-performance json validation
Last synced: about 1 month ago
JSON representation
High performance JSON iterator & validator for Go
- Host: GitHub
- URL: https://github.com/romshark/jscan
- Owner: romshark
- License: bsd-3-clause
- Created: 2022-01-08T03:28:41.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-02T18:24:10.000Z (11 months ago)
- Last Synced: 2024-07-31T20:52:04.413Z (5 months ago)
- Topics: go, golang, high-performance, json, validation
- Language: Go
- Homepage:
- Size: 8.27 MB
- Stars: 87
- Watchers: 6
- Forks: 7
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - jscan - High performance zero-allocation JSON iterator. (JSON / Search and Analytic Databases)
- awesome-go-extra - jscan - 01-08T03:28:41Z|2022-01-25T05:59:22Z| (JSON / Advanced Console UIs)
README
# jscan
jscan provides high-performance zero-allocation JSON iterator and validator for Go. This module doesn't provide `Marshal`/`Unmarshal` capabilities *yet*, instead it focuses on highly efficient iteration over JSON data with on-the-fly validation.An [experimental decoder](https://github.com/romshark/jscan-experimental-decoder) with backward compatibility to [encoding/json](https://pkg.go.dev/encoding/json) is WiP ๐งช and is expected to be introduced together with jscan v3.
jscan is tested against https://github.com/nst/JSONTestSuite, a comprehensive test suite for [RFC 8259](https://datatracker.ietf.org/doc/html/rfc8259) compliant JSON parsers.
See [jscan-benchmark](https://github.com/romshark/jscan-benchmark) for benchmark results ๐๏ธ ๐.
## Example
https://go.dev/play/p/moP3l9EkebF```go
package mainimport (
"fmt""github.com/romshark/jscan/v2"
)func main() {
j := `{
"s": "value",
"t": true,
"f": false,
"0": null,
"n": -9.123e3,
"o0": {},
"a0": [],
"o": {
"k": "\"v\"",
"a": [
true,
null,
"item",
-67.02e9,
["foo"]
]
},
"a3": [
0,
{
"a3.a3":8
}
]
}`err := jscan.Scan(j, func(i *jscan.Iterator[string]) (err bool) {
fmt.Printf("%q:\n", i.Pointer())
fmt.Printf("โโ valueType: %s\n", i.ValueType().String())
if k := i.Key(); k != "" {
fmt.Printf("โโ key: %q\n", k[1:len(k)-1])
}
if ai := i.ArrayIndex(); ai != -1 {
fmt.Printf("โโ arrayIndex: %d\n", ai)
}
if v := i.Value(); v != "" {
fmt.Printf("โโ value: %q\n", v)
}
fmt.Printf("โโ level: %d\n", i.Level())
return false // Resume scanning
})if err.IsErr() {
fmt.Printf("ERR: %s\n", err)
return
}
}
```