import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 import html as html_module # List of empty values that we want to filter out. EMPTY_VALUES = [ "{}", "[{}]", "[{}, {}]", "[{}, {}, {}]", "0001-01-01T00:00:00Z", "containmentsla", "remediationsla", "detectionsla", "triagesla", ] def extract_keys_with_values(obj, parent_key=""): """ Extracts the keys with values in the JSON object """ items = [] for k, v in obj.items(): new_key = f"{parent_key}.{k}" if parent_key else k if isinstance(v, dict): items.extend(extract_keys_with_values(v, new_key)) else: items.append((new_key, v)) return items def escape_for_html_table(value): """Escape value for safe insertion into HTML table cells.""" return html_module.escape(str(value)) def format_data_to_rows(items): """ Formats the extracted data into (key, value) rows. Each row is kept as a tuple rather than a pipe-delimited string so that values that themselves contain the pipe character are never split into extra table columns. """ rows = [] for key, value in items: if isinstance(value, list): # If the value is a list, join the items with a comma for display value = ", ".join(map(str, value)) rows.append((str(key), str(value))) return rows def convert_to_html(rows): html = [ """
| {escape_for_html_table(column)} | ') html.append("