Skip to content

Latest commit

 

History

History
67 lines (50 loc) · 2.11 KB

README.md

File metadata and controls

67 lines (50 loc) · 2.11 KB

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