Member-only story
CSV to JSON with Python for MySQL upload
Admittedly, I have jumped head-first into the world of JSON
within MySQL. I also have a thing for Python, of which I find myself using a lot of in my day job as Pipeline Survey Data Analyst. CSV’s are everywhere: in data at work, on the web, even in my personal life (as you’ll see). Loading CSV data into MySQL is nothing new to anyone working with either of the technologies. As a matter of fact, there are several ways you can get your CSV data into MySQL. I wrote the post, Pyodbc SQL CRUD – Create: Examples with MySQL, you can read where I cover loading CSV data using the Python pyodbc
module. But, how about type-casting CSV data – which typically are strings – to a compatible JSON
data type? Then push the JSON
data to a MySQL JSON
column? And that my friends, is the focus of this post. Turns out, Python’s csv
and json
standard libraries make the whole process virtually painless. Keep reading and see a simple script I devised…
OS, Software, and DB used:
- OpenSuse Leap 15.1
- Python 3.7.3
Self-Promotion:
If you enjoy the content written here, by all means, share this blog and your favorite post(s) with others who may benefit from or like it as well. Since coffee is my favorite drink, you can even buy me one if you would like!