import json


def load_extract_row(row_str):
    """Load Panoptes extract row into memory.
    Sensitive to export schema changes - should only be used on existing data.
    All new classifications should be downloaded via Panoptes API.
    
    Args:
        row_str (str): single line of Panoptes workflow classifications export
    
    Returns:
        dict: all data from the string, with nested dicts for annotations, metadata, subject_data
    """
    result = {}
    opening_str, metadata_and_annotations, subject_str_and_closing = row_str.split('"{"')
    opening_data = opening_str.split(',')
    # if these ever change, we'll be in trouble, hence this should only be used for past exports
    result['classification_id'] = opening_data[0]
    result['user_name'] = opening_data[1]
    result['user_id'] = opening_data[2]
    result['user_ip'] = opening_data[3]
    result['workflow_id'] = opening_data[4]
    result['workflow_name'] = opening_data[5]
    result['workflow_version'] = opening_data[6]
    result['created_at'] = opening_data[7]
    result['gold_standard'] = opening_data[8]
    result['expert'] = opening_data[9]

    metadata_str, annotations_str = metadata_and_annotations.split('"[{"')
    metadata_str_to_load = '{' + metadata_str[:-2].replace('""', '"').strip("'")
    result['metadata'] = json.loads(metadata_str_to_load)

    annotations_str_to_load = '[{' + annotations_str[:-2].replace('""', '"')
    result['annotations'] = json.loads(annotations_str_to_load)

    subject_str, closing_str = subject_str_and_closing.split('}",')
    subject_str_to_load = ('{"' + subject_str + '}').replace('""', '"')
    result['subject_data'] = json.loads(subject_str_to_load)

    result['subject_ids'] = closing_str

    return result