Skip to content

Eriner/jsonl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonl

A Go package to provide jsonl support.

Go Reference

Package is WIP and unstable.

About

JSON Lines is very useful when creating power-loss resistant applications. Without JSON Lines, you risk a power loss corrupting half of a write.

From my memory the Ubiquiti CloudKey Gen 1, lacking a battery, had a similar problem: configuration/database writes could corrupt the device such that it would not boot.

The use of JSONL as opposed to regular JSON solves this problem.

Usage

store, err := jsonl.OpenFile("config.jsonl")
if err != nil {
	panic(err)
}
defer store.Close()

reader := json.NewDecoder(store)
writer := json.NewEncoder(store)

data := struct{
	Key string
}{
	Key: "value",
}

if err := writer.Encode(&data); err != nil {
	panic(err)
}
if err := reader.Decode(&data); err != nil {
	panic(err)
}
log.Printf("%+v\n", data)

About

JSON Lines for Go. Unstable package.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages