Created
December 9, 2024 17:37
-
-
Save aurbano/008e55ce8c69fc00c84a48a00d66ac2b to your computer and use it in GitHub Desktop.
Threat Dragon JSON to CSV
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import csv | |
input_file = "threat-model_threat-dragon.json" | |
output_file = "threat_model.csv" | |
with open(input_file, "r") as f: | |
data = json.load(f) | |
with open(output_file, "w", newline="") as csvfile: | |
csvwriter = csv.writer(csvfile) | |
header = ["Threat ID", "Component", "Type", "Title", "Description", "Severity", "Mitigation", "Status"] | |
csvwriter.writerow(header) | |
cells = data["detail"]["diagrams"][0]["cells"] | |
threats = data.get("threats", []) | |
for cell in cells: | |
if "data" not in cell or "threats" not in cell["data"]: | |
continue | |
for threat in cell["data"]["threats"]: | |
threat_id = f"TM-{threat['number']}" | |
component = cell["data"]["name"] | |
sectype = threat.get("type", "") | |
title = threat.get("title", "") | |
description = threat.get("description", "") | |
severity = threat.get("severity", "") | |
mitigation = threat.get("mitigation", "") | |
status = threat.get("status", "") | |
csvwriter.writerow([threat_id, component, sectype, title, description, severity, mitigation, status]) | |
print(f"Threat model converted to {output_file}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment