Gojson is a lightweight and fast JSON parser for Go. It is inspired by gjson, but adds a new Set
method to make it easier to modify existing JSON documents.
To install gojson, use go get
:
go get github.com/leowilbur/gojson
Gojson provides a simple API for parsing and manipulating JSON documents.
To parse a JSON document, use the Parse
function:
data := `{"name": "John Doe", "age": 42}`
json, err := gojson.Parse(data)
if err != nil {
// handle error
}
Once you have parsed a JSON document, you can access its values using the Get
method:
name := json.Get("name").String() // "John Doe"
age := json.Get("age").Int() // 42
Gojson also provides a Set
method for modifying existing values in a JSON document:
gojson.Set("name", "Jane Doe")
gojson.Set("age", 43)
To serialize a JSON document, use the String
method:
data := json.String() // {"name": "Jane Doe", "age": 43}
Gojson is released under the MIT license. See LICENSE for details.