import json import pandas as pd crop = 'wheat' # Read the JSON file with open(('Downloads/' + crop + '.json'),'r') as file: data = json.load(file) # Prepare the data for the DataFrame records = [] for key, value in data.items(): record = { "FieldID": value.get("FieldID"), "FieldAddress": value.get("FieldAddress", "-"), "FieldDescription": value.get("FieldDescription", "-"), "FieldArea": round((float(value.get("FieldArea", 0))/4047),2), "Name": value.get("Name", "-"), "Phone": value.get("Phone", "-") } records.append(record) # Create a DataFrame df = pd.DataFrame(records, columns=["FieldID", "FieldAddress", "FieldDescription", "FieldArea", "Name", "Phone"]) # Write the DataFrame to an Excel file excel_file_path = 'agrimisr_' + crop + '_fields_data.xlsx' df.to_excel(excel_file_path, index=False) print(f"Excel file created successfully at: {excel_file_path}")