import re
import json


def prettyprint(data, indent = 4, sort_keys = True, noprint = False):
    """Nicer version of pprint (which is actually kind of ugly)

    Note: assumes that input data can be dumped to json (typically a list or dict)
    """
    pattern = re.compile(r'^', re.MULTILINE)
    spaces = ' ' * indent
    if noprint:
        return re.sub(pattern, spaces, json.dumps(data, indent=indent, sort_keys=sort_keys, ensure_ascii=False))
    else:
        print(re.sub(pattern, spaces, json.dumps(data, indent=indent, sort_keys=sort_keys, ensure_ascii=False)))