Created
May 18, 2017 08:58
-
-
Save danielfbm/1ba74af0c4bb2cfa99673d54d7cfe3cf to your computer and use it in GitHub Desktop.
change a json key's value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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