func flattenKeys(m map[string]interface{}, keys []string) {
	keyMap := make(map[string]struct{})
	for _, key := range keys {
		keyMap[key] = struct{}{}
	}

	var flatten func(map[string]interface{}, string)
	flatten = func(m map[string]interface{}, parent string) {
		for k, v := range m {
			// Calculate the map key, since it could include a parent.
			mapKey := k
			if parent != "" {
				mapKey = parent + "." + k
			}

			if _, ok := keyMap[mapKey]; !ok {
				continue
			}

			switch typed := v.(type) {
			case []map[string]interface{}:
				if len(typed) > 0 {
					last := typed[len(typed)-1]
					flatten(last, mapKey)
					m[k] = last
				} else {
					m[k] = nil
				}
			case map[string]interface{}:
				flatten(typed, mapKey)
				m[k] = typed
			default:
				m[k] = v
			}
		}
	}

	flatten(m, "")
}
func flattenKeys(m map[string]interface{}, keys []string) {
	keyMap := make(map[string]struct{})
	for _, key := range keys {
		keyMap[key] = struct{}{}
	}

	var flatten func(map[string]interface{}, string)
	flatten = func(m map[string]interface{}, parent string) {
		for k, v := range m {
			
			mapKey := k
			if parent != "" {
				mapKey = parent + "." + k
			}

			if _, ok := keyMap[mapKey]; !ok {
				continue
			}

			switch typed := v.(type) {
			case []map[string]interface{}:
				if len(typed) > 0 {
					last := typed[len(typed)-1]
					flatten(last, mapKey)
					m[k] = last
				} else {
					m[k] = nil
				}
			case map[string]interface{}:
				flatten(typed, mapKey)
				m[k] = typed
			default:
				m[k] = v
			}
		}
	}

	flatten(m, "")
}
func flattenKeys ( m map [ string ] interface { } , keys [ ] string ) { keyMap := make ( map [ string ] struct { } ) for _ , key := range keys { keyMap [ key ] = struct { } { } } var flatten func ( map [ string ] interface { } , string ) flatten = func ( m map [ string ] interface { } , parent string ) { for k , v := range m { // Calculate the map key, since it could include a parent. mapKey := k if parent != " " { mapKey = parent + " " + k } if _ , ok := keyMap [ mapKey ] ; ! ok { continue } switch typed := v . ( type ) { case [ ] map [ string ] interface { } : if len ( typed ) > 0 { last := typed [ len ( typed ) - 1 ] flatten ( last , mapKey ) m [ k ] = last } else { m [ k ] = nil } case map [ string ] interface { } : flatten ( typed , mapKey ) m [ k ] = typed default : m [ k ] = v } } } flatten ( m , " " ) }
// flattenKeys is a function that takes a map[string]interface{} and recursively
// flattens any keys that are a []map[string]interface{} where the key is in the
// given list of keys.
flattenKeys is a function that takes a map [ string ] interface {} and recursively flattens any keys that are a [] map [ string ] interface {} where the key is in the given list of keys .