Skip to content
Work with go maps using json like paths
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
gjm.go
gjm_test.go
helpers.go

README.md

Build Status Godoc license

Go json map

Using this package you can [Get/Create/Update/Delete] your map's nested properties as easy as json.

For example:

document := map[string]interface{}{
	"one": map[string]interface{}{
		"two": map[string]interface{}{
			"three": []int{
				1, 2, 3,
			},
		},
		"four": map[string]interface{}{
			"five": []int{
				11, 22, 33,
			},
		},
	},
}

Get a property

property, err := GetProperty(document, "one.two.three[0]")
fmt.Println(property)
// property => 1

property, err = GetProperty(document, "one.two.three", ".")
fmt.Println(property)
// property => 1, 2, 3

Create

err := CreateProperty(document, "one.three", "third value")

Update

err := UpdateProperty(document, "one.two.three[0]", "updated value")
err := UpdateProperty(document, "one/two/three[4]", []int{1,2,3,4}, "/")

Delete

err := DeleteProperty(document, "one.four")
err := DeleteProperty(document, "one.two.three[3]")
You can’t perform that action at this time.