README

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]")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddProperty

func AddProperty(original_data map[string]interface{}, path string, value interface{}, separator_arr ...string) (err error)

    AddProperty adds a property to map. Returns an error if property already exists

    err := AddProperty(document, "one.two.three[0]", "string value")
    err := AddProperty(document, "one.two.three[0]", "string value", ".")
    err := AddProperty(document, "one/two/three[0]", "string value", "/")
    

    func DeleteProperty

    func DeleteProperty(original_data map[string]interface{}, path string, separator_arr ...string) (err error)

      DeleteProperty removes a property from map

      err := DeleteProperty(document, "one.two.three[0]")
      err := DeleteProperty(document, "one.two.three[0]", ".")
      err := DeleteProperty(document, "one/two/three[0]", "/")
      

      func GetProperty

      func GetProperty(original_data map[string]interface{}, path string, separator_arr ...string) (path_parsed interface{}, err error)

        GetProperty returns a property if it exist.

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

        Property type is `interface{}`

        func UpdateProperty

        func UpdateProperty(original_data map[string]interface{}, path string, value interface{}, separator_arr ...string) (err error)

          UpdateProperty updates a property in a map. It will create or update existing property

          err := UpdateProperty(document, "one.two.three[0]", "string value")
          err := UpdateProperty(document, "one.two.three[0]", "string value", ".")
          err := UpdateProperty(document, "one/two/three[0]", "string value", "/")
          

          Types

          This section is empty.

          Source Files