Skip to content

Instantly share code, notes, and snippets.

@billiepander
Created August 24, 2017 06:54
Show Gist options
  • Select an option

  • Save billiepander/7caa81f3fba3054a8c6bd5fef510f373 to your computer and use it in GitHub Desktop.

Select an option

Save billiepander/7caa81f3fba3054a8c6bd5fef510f373 to your computer and use it in GitHub Desktop.
func NestedMapToFlatMap(a_map map[string]interface{}) map[string]interface{} {
new_map := map[string]interface{}{}
for key, val := range a_map{
t:=reflect.TypeOf(val)
if t.Kind() == reflect.Map{
mapval, _ := val.(map[string]interface{})
for i,j :=range mapval{
new_map[i] = j
}
} else {
new_map[key] = val
}
}
for _, val := range new_map{
t:=reflect.TypeOf(val)
if t.Kind() == reflect.Map{
new_map = NestedMapToFlatMap(new_map)
}
}
return new_map
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment