Skip to content

Go package to read and process JSON files without static typing and marshaling.

License

Notifications You must be signed in to change notification settings

tideland/go-dynaj

Repository files navigation

Tideland Go Dynamic JSON

GitHub release GitHub license Go Module GoDoc Workflow Go Report Card

Description

Tideland Go Dynamic JSON provides a simple dynamic handling of JSON documents. Values can be retrieved, set and added by paths like "foo/bar/3". Methods provide typesafe access to the values as well as flat and deep processing.

doc, err := dynaj.Unmarshal(myDoc)
if err != nil {
    ...
}
name := doc.ValueAt("/name").AsString("")
street := doc.ValueAt("/address/street").AsString("unknown")

Another way is to create an empty document with

doc := dynaj.NewDocument()

Here as well as in parsed documents values can be set with

err := doc.SetValueAt("/a/b/3/c", 4711)

Additionally values of the document can be processed recursively using

err := doc.Root().Process(func(node *dynaj.Node) error {
    ...
})

or from deeper nodes with doc.ValueAt("/a/b/3").Process(...). Additionally flat processing is possible with

err := doc.ValueAt("/x/y/z").Range(func(node *dynaj.Node) error {
    ...
})

To retrieve the differences between two documents the function dynaj.Compare() can be used:

diff, err := dynaj.Compare(firstDoc, secondDoc)

privides a dynaj.Diff instance which helps to compare individual paths of the two document.

Contributors

About

Go package to read and process JSON files without static typing and marshaling.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages