import json


def format_json(d, compact=False, indent=2):
    """Format JSON; compact or indented."""
    separators = (',', ':') if compact else None
    return json.dumps(d, indent=indent, separators=separators)