https://github.com/bfontaine/jsons
:briefcase: Read & write .jsons files in Go
https://github.com/bfontaine/jsons
go json library
Last synced: about 1 year ago
JSON representation
:briefcase: Read & write .jsons files in Go
- Host: GitHub
- URL: https://github.com/bfontaine/jsons
- Owner: bfontaine
- License: mit
- Created: 2015-07-12T19:21:24.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2022-10-20T10:13:57.000Z (over 3 years ago)
- Last Synced: 2025-04-10T06:20:48.756Z (about 1 year ago)
- Topics: go, json, library
- Language: Go
- Homepage: https://godoc.org/github.com/bfontaine/jsons
- Size: 13.7 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jsons
[](https://travis-ci.org/bfontaine/jsons)
[](https://godoc.org/github.com/bfontaine/jsons)
**jsons** is a Go library to work with JSONS/[NDJSON][] files.
JSONS files contain JSON objects, one per line. This storage format is more
efficient than storing an array of objects since it doesn’t need to be loaded
in memory when reading/writing it.
[NDJSON]: http://ndjson.org/
## Install
go get github.com/bfontaine/jsons
## Usage
### Reading
```go
func read() {
j := jsons.NewFileReader("foo.jsons")
if err := j.Open(); err != nil {
log.Fatal(err)
}
defer j.Close()
for {
var m map[string]string
if err := j.Next(&m); err != nil {
if err == io.EOF {
break
}
log.Fatal(err)
}
log.Printf("got %+v", m)
}
}
```
### Writing
```go
func write() {
j := jsons.NewFileWriter("foo.jsons")
if err := j.Open(); err != nil {
log.Fatal(err)
}
defer j.Close()
j.Add(map[string]string{
"foo": "bar",
"qux": "abc",
})
j.Add(map[string]string{
"foo": "def",
"ghi": "jkl",
"mno": "qpr",
})
}
```