https://github.com/oneofone/jsonex
https://github.com/oneofone/jsonex
go json
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/oneofone/jsonex
- Owner: OneOfOne
- License: bsd-3-clause
- Created: 2023-04-19T15:52:13.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-19T15:57:23.000Z (about 3 years ago)
- Last Synced: 2025-01-21T05:25:08.066Z (over 1 year ago)
- Topics: go, json
- Language: Go
- Homepage: https://go.oneofone.dev/jsonex
- Size: 188 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonex: A simple fork of `encoding/json`
This package is a fork of `encoding/json` that allows decoding individual JSON slice and map items. It is intended to be used in conjunction with `jsonex.Decoder` to allow decoding of large JSON files without loading the entire file into memory.
It adds 2 functions `DecodeKey` and `DecodeValue` that allow decoding of individual JSON slice and map items.
Synced with [Go](https://github.com/golang/go/tree/9cad0cc6e6b2a84134c46ce7069e62de28459f26) on 2023-04-19.
## Example
```go
package main
import (
"fmt"
"strings"
"go.oneofone.dev/jsonex"
)
func main() {
dec := jsonex.NewDecoder(strings.NewReader(`{"foo": "bar", "baz": "qux"}`))
// Decode the first key
key, err := dec.DecodeKey()
if err != nil {
panic(err)
}
fmt.Println(key)
// Decode the first value
var value string
err = dec.DecodeValue(&value)
if err != nil {
panic(err)
}
fmt.Println(value)
// Decode the second key
key, err = dec.DecodeKey()
if err != nil {
panic(err)
}
fmt.Println(key)
// Decode the second value
err = dec.DecodeValue(&value)
if err != nil {
panic(err)
}
fmt.Println(value)
}
```
More examples in [decode_ex_test.go](decode_ex_test.go).
## License
Same as Go's `encoding/json` package. See [LICENSE](LICENSE) for details.