def prettyjson(json, indentation='  '):
    """Formats a Python-object into a string in a JSON like way, but
    uses triple quotes for multiline strings.

    PARAMETERS:
    json        -- Python object that is serializable into json.
    indentation -- str; represents one level of indentation

    NOTES:
    All multiline strings are treated as raw strings.

    RETURNS:
    str; the formatted json-like string.
    """
    if isinstance(json, int) or isinstance(json, float):
        return str(json)
    elif isinstance(json, str):
        if '\n' in json:
            return 'r"""\n' + dedent(json) + '\n"""'
        return repr(json)
    elif isinstance(json, list):
        lst = [indent(prettyjson(el, indentation), indentation) for el in json]
        return '[\n' + ',\n'.join(lst) + '\n]'
    elif isinstance(json, dict):
        pairs = []
        for k, v in sorted(json.items()):
            k = prettyjson(k, indentation)
            v = prettyjson(v, indentation)
            pairs.append(indent(k + ': ' + v, indentation))
        return '{\n' + ',\n'.join(pairs) + '\n}'
    else:
        raise exceptions.SerializeException('Invalid json type: {}'.format(json))
def prettyjson ( json , indentation = '  ' ) : if isinstance ( json , int ) or isinstance ( json , float ) : return str ( json ) elif isinstance ( json , str ) : if '\n' in json : return 'r"""\n' + dedent ( json ) + '\n"""' return repr ( json ) elif isinstance ( json , list ) : lst = [ indent ( prettyjson ( el , indentation ) , indentation ) for el in json ] return '[\n' + ',\n' . join ( lst ) + '\n]' elif isinstance ( json , dict ) : pairs = [ ] for k , v in sorted ( json . items ( ) ) : k = prettyjson ( k , indentation ) v = prettyjson ( v , indentation ) pairs . append ( indent ( k + ': ' + v , indentation ) ) return '{\n' + ',\n' . join ( pairs ) + '\n}' else : raise exceptions . SerializeException ( 'Invalid json type: {}' . format ( json ) )
Formats a Python-object into a string in a JSON like way, but
    uses triple quotes for multiline strings.

    PARAMETERS:
    json        -- Python object that is serializable into json.
    indentation -- str; represents one level of indentation

    NOTES:
    All multiline strings are treated as raw strings.

    RETURNS:
    str; the formatted json-like string.