import json


def json_dumps(obj, pretty: bool) -> str:
    """Generate JSON, optionally with pretty printing."""
    return (json.dumps(obj) if not pretty else
            json.dumps(obj, indent=4, sort_keys=True))