forked from dsto97/CWEParser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert_json.py
32 lines (24 loc) · 903 Bytes
/
convert_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import json
import pandas as pd
# Specify the JSON file path
json_file_path = r"\file_path"
# Open the JSON file and read its content
with open(json_file_path, 'r', encoding='utf-8') as file:
json_data = json.load(file)
# Extract 'id', 'name', and 'description' from each object under "CWE"
data_list = []
if "CWE" in json_data:
for item in json_data["CWE"]:
if isinstance(item, dict):
data_list.append({
'id': item.get('id'),
'name': item.get('name'),
'description': item.get('description')
})
# Convert to DataFrame
df = pd.DataFrame(data_list)
# Specify the Excel file path
excel_file_path = 'output.xlsx'
# Write DataFrame to Excel
df.to_excel(excel_file_path, index=False)
print(f"Data from {json_file_path} has been successfully parsed and saved to {excel_file_path}")