def format_dict(d):
    """ Format nested dictionaries to a readable string. """
    s = ['']
    def helper(d, s, depth=0):
        for k,v in sorted(d.items(), key=lambda x: x[0]):
            if isinstance(v, dict):
                s[0] += ("  ")*depth + ("%s: {" % k) + ',\n'
                helper(v, s, depth+1)
                s[0] += ("  ")*depth + ("}") + ',\n'
            else:
                s[0] += ("  ")*depth + "%s: %s" % (k, v) + ',\n'
    helper(d, s)
    return s[0]