def normalize_dotted_fields(document):
 if isinstance(document, list):
  prev = document
  for i in prev:
   normalize_dotted_fields(i)
 elif isinstance(document, dict):
  for field in list(document):
   if ('.' in field):
    parts = field.split('.')
    prev = document
    for part in parts[:(-1)]:
     if (part not in prev):
      prev[part] = {}
     prev = prev[part]
    if isinstance(document[field], (dict, list)):
     normalize_dotted_fields(document[field])
    prev[parts[(-1)]] = document[field]
    document.pop(field)
   elif isinstance(document[field], (dict, list)):
    normalize_dotted_fields(document[field])

def normalize_dotted_fields ( document ) : if isinstance ( document , list ) : prev = document for i in prev : normalize_dotted_fields ( i ) elif isinstance ( document , dict ) : for field in list ( document ) : if ( '.' in field ) : parts = field . split ( '.' ) prev = document for part in parts [ : ( - 1 ) ] : if ( part not in prev ) : prev [ part ] = { } prev = prev [ part ] if isinstance ( document [ field ] , ( dict , list ) ) : normalize_dotted_fields ( document [ field ] ) prev [ parts [ ( - 1 ) ] ] = document [ field ] document . pop ( field ) elif isinstance ( document [ field ] , ( dict , list ) ) : normalize_dotted_fields ( document [ field ] )
normalizes eventual dotted fields so validation can be performed seamlessly .