import pandas as pd
import json
Load the JSON file
with open('test-state.json') as f:
data = json.load(f)
Create an empty Pandas dataframe
df = pd.DataFrame(columns=['block_number', 'transaction_hash', 'transaction_index', 'from', 'to', 'value', 'timestamp'])
Loop through the JSON data and extract the necessary fields
for block_number, block_data in data['blocks'].items():
for transaction_hash, transaction_data in block_data.items():
for transaction_index, transaction_info in transaction_data.items():
df = df.append({
'block_number': block_number,
'transaction_hash': transaction_hash,
'transaction_index': transaction_index,
'from': transaction_info['from'],
'to': transaction_info['to'],
'value': transaction_info['value'],
'timestamp': transaction_info['timestamp']
}, ignore_index=True)
Print the resulting dataframe
df.to_csv('output_data.csv', sep=',')