Data-Forums Data-ForumsAI · data · automation · Gaming
Create an account

New here? Join Data-Forums — ask questions, share builds & trade smarter with us.Sign up freeLog in×

Thread

How do I convert CSV to JSON in Python (and back)?

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
1 total views  ·  1 guest view

#1
Three ways, from quickest to most control:

1. pandas
Code:
import pandas as pd df = pd.read_csv('data.csv') df.to_json('data.json', orient='records')

2. csv + json modules (no dependencies)
Code:
import csv, json with open('data.csv') as f: rows = list(csv.DictReader(f)) with open('data.json', 'w') as f: json.dump(rows, f, indent=2)

3. DF Toolbox – for quick one-off conversions the CSV ⇄ JSON converter on tools.php does both directions instantly, no code needed.

Watch out for: encoding (use encoding='utf-8'), and numbers stored as strings (convert them explicitly).

How do you handle the CSV → JSON step in your pipelines – code, tooling, or both?
Reply

Users browsing this thread:
1 Guest(s)

Forum Jump:
Join AI builders shipping real tools. No hype, no guru courses — just post-mortems, prompts, and people who build.

The community for AI engineers, automation builders, prompt crafters, cybersecurity folks & data practitioners. Talk about what ships — not what trends.

18k+
Posts
1.8k
Threads
112+
Members
Online
© 2026 Data-Forums · Built with by Sir-VIGU · Powered By MyBB