import re
import ast


def _parse_data_structure(inner_json):
    """Parses broken JSON that this router generates.

    Data structures look like this:
    {
        key: 'value',
        another_key: [1, 2, 3]
    }

    We're basically using what's between the main {},
    and are parsing that, returning a dictionary.
    """

    results = {}
    for line in inner_json.split('\n'):
        match_object = re.compile('^\s+(.+?):\s(.+?),?$').match(line)
        if match_object is None:
                continue
        key, value = match_object.groups()
        try:
            results[key] = ast.literal_eval(value)
        except ValueError:
            pass
    return results