Skip to content

Instantly share code, notes, and snippets.

@danielfbm
Created May 18, 2017 08:58
Show Gist options
  • Save danielfbm/1ba74af0c4bb2cfa99673d54d7cfe3cf to your computer and use it in GitHub Desktop.
Save danielfbm/1ba74af0c4bb2cfa99673d54d7cfe3cf to your computer and use it in GitHub Desktop.
change a json key's value
package main
func main() {
var data interface{}
ctx.ReadJSON(&data)
if obj, ok := data.(map[string]interface{}); ok {
obj["name"] = ""
} else if array, ok := data.([]interface{}); ok {
data = checkArray(array)
}
func checkArray(array []interface{}) []interface{} {
for i, item := range array {
if innerObj, iOk := item.(map[string]interface{}); iOk {
innerObj["name"] = ""
} else if innerArr, aOk := item.([]interface{}); aOk {
array[i] = checkArray(innerArr)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment