Created
August 24, 2017 06:54
-
-
Save billiepander/7caa81f3fba3054a8c6bd5fef510f373 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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