Created
September 1, 2024 03:52
-
-
Save mvark/0efb9a1ffa28caba87df7e7d24da46c1 to your computer and use it in GitHub Desktop.
Python script to convert a JSON file to CSV. This script loads JSON data from a file, converts it into a structured pandas DataFrame, and then saves that DataFrame as a CSV file. The main steps involve reading the JSON file, normalizing the JSON structure into a flat format (suitable for tabular data), and finally exporting that data into a 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 pandas as pd | |
# Load JSON data, specify the file name with JSON content | |
with open(r'C:\OFF\raw.json') as f: | |
data = json.load(f) | |
# Convert to DataFrame | |
df = pd.json_normalize(data['products']) | |
# Save to CSV | |
df.to_csv(r'C:\OFF\products.csv', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment