-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
33 lines (24 loc) · 862 Bytes
/
Copy pathmain.py
File metadata and controls
33 lines (24 loc) · 862 Bytes
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 pandas as pd
import json
import re
def excel_to_json(excel_file, column_name):
# Read the Excel file
df = pd.read_excel(excel_file)
# Iterate over each cell in the specified column
for cell in df[column_name]:
# Create a JSON file for each cell
match = re.search('{"id":"(.+?)","', cell)
if match:
file_name = match.group(1) + '.json'
cell = json.loads(cell)
with open("json/" + file_name, 'w') as file:
json.dump(cell, file)
print(f'{file_name} created successfully!')
else:
print(f'File creation failed: {cell}')
print('JSON files created successfully!')
# Specify the Excel file path and column name
excel_file = './json.xlsx'
column_name = 'json'
# Call the function
excel_to_json(excel_file, column_name)