Eriner / jsonl

JSON Lines for Go. Unstable package.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

License:MIT License


Languages

Language:Go 100.0%