def collapse_json(text, indent=12):
    """Compacts a string of json data by collapsing whitespace after the
    specified indent level

    NOTE: will not produce correct results when indent level is not a multiple
    of the json indent level
    """
    initial = ' ' * indent
    out = []
    sublevel = []
    pending = None
    for line in text.splitlines():
        if line.startswith(initial):
            if line[indent] == ' ':
                if pending:
                    sublevel.append(pending)
                    pending = None
                item = line.strip()
                sublevel.append(item)
                if item.endswith(','):
                    sublevel.append(' ')
            elif sublevel:
                sublevel.append(line.strip())
                out.append(''.join(sublevel))
                sublevel = []
            else:
                if pending:
                    out.append(pending)
                pending = line.rstrip()
        else:
            if pending:
                out.append(pending)
                pending = None
            if sublevel:
                out.append(''.join(sublevel))
            out.append(line)
    return '\n'.join(out)
