(data)
Pretty-formats `data` for readability, or returns the original
    value if it can't be parsed as JSON.

    :return: A 2-space-indented string with sorted keys.
Pretty-formats `data` for readability, or returns the original
    value if it can't be parsed as JSON.
Pretty - formats data for readability or returns the original value if it can t be parsed as JSON .
def pformat_json(data):
    """
    Pretty-formats `data` for readability, or returns the original
    value if it can't be parsed as JSON.

    :return: A 2-space-indented string with sorted keys.
    """
    if data is None:
        return ''
    try:
        json_data = json.loads(data) if isinstance(data, (str, bytes)) else data
        return json.dumps(json_data, indent=2, sort_keys=True)
    except (TypeError, ValueError):
        return data
def pformat_json ( data ) : if data is None : return '' try : json_data = json . loads ( data ) if isinstance ( data , ( str , bytes ) ) else data return json . dumps ( json_data , indent = 2 , sort_keys = True ) except ( TypeError , ValueError ) : return data