A Go library for dealing with deserialized data for which the structure is dynamic or unknown.
Installation • How to use • Credits • License
go get github.com/macabot/solenodon
Solenodon must be used in combination with a serialization library that is able to deserialize data into a tree structure of maps and slices given a target of type interface{}
.
Supported:
Unsupported:
- encoding/xml - because there is no standard way to map XML to a key-value structure.
The following shows an example of how to use the Has
, Get
, Delete
and SetData
method:
raw := []byte(`{"foo":"bar","items":[2,3,{"i":6,"j":7}]}`)
container, err := solenodon.NewContainerFromBytes(raw, json.Unmarshal)
if err != nil {
panic(err)
}
fmt.Println(container.Has("foo")) // true
fmt.Println(container.Get("foo").Data().(string)) // bar
container.Get("items", 2, "j").SetData(44)
container.Delete("items", 0)
b, err := json.Marshal(container.Data())
if err != nil {
panic(err)
}
fmt.Println(string(b)) // {"foo":"bar","items":[3,{"i":6,"j":44}]}
You can find more examples here.
This library was inspired by gabs.
Solenodon is made available under the MIT License.