All Projects → firewut → go-json-map

firewut / go-json-map

Licence: MIT license
Work with go maps using json like paths

Programming Languages

go
31211 projects - #10 most used programming language

Labels

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]")
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].