def _dict_to_name_value(data):
 if isinstance(data, dict):
  sorted_data = sorted(data.items(), key=(lambda s: s[0]))
  result = []
  for (name, value) in sorted_data:
   if isinstance(value, dict):
    result.append({name: _dict_to_name_value(value)})
   else:
    result.append({name: value})
 else:
  result = data
 return result

def _dict_to_name_value ( data ) : if isinstance ( data , dict ) : sorted_data = sorted ( data . items ( ) , key = ( lambda s : s [ 0 ] ) ) result = [ ] for ( name , value ) in sorted_data : if isinstance ( value , dict ) : result . append ( { name : _dict_to_name_value ( value ) } ) else : result . append ( { name : value } ) else : result = data return result
convert a dictionary to a list of dictionaries to facilitate ordering .