try: metadata = metadata['properties'] except KeyError: pass