 Okay, today we're going to be looking at converting CSV files to JSON format. We're going to use Python, but we're going to use it in a Python one-liner so we can put it in shell scripts as well. So real quick, what is a CSV file? Let me cat this out. I have a file in here I just created, very simple. Think of it as a spreadsheet, because if you create a spreadsheet, CSVs are very common plain text format. If you have a database or a spreadsheet, usually your application will allow you to export to CSV format, which basically is comma separated values or comma separated, I always say values, but it's not values, it's comma separated something. So basically think of this as a spreadsheet, but each cell is divided by a comma. So actually if I was to, let me just open LibreOffice and open up spreadsheets and say open and I'm going to go to temp, tutorial, there we go. And right here I can say open and you can see it's a spreadsheet. I've got, you know, names here, addresses here, phone numbers here. So if you have a file like this, you can go down to export and choose CSV, not there. Maybe you have to use export option or save as, there we go. And in here somewhere is going to be a CSV file right there. And again, it's just a plain text file that allows you to create tables and spreadsheets and stuff or at least export them to a format that you can read and use in scripts and whatnot. So I have this CSV file, which is a very common file and I use them in scripts sometimes, but if the data gets more complex or if you just prefer, which I do, using JSON, which JSON is a JavaScript, I forget what the acronym stands for, but basically it's a format that is very easy to work with when you're working with data such as this, not only in JavaScript, but other languages too, but primarily for me in JavaScript. So if I have a spreadsheet or CSV file and I want to create a JSON file for me to use an application, how do I do that? Well, again, like I said, I'm going to use Python. So I'm going to show you here in Python, but I'm going to use as a Python one-liner that you can use in a shell script as well. So I'm in the Python command line here and what I'm going to do is I'm going to say import. I'm going to import two modules. I'm going to import the CSV module and the JSON module. So what it's going to do is allow us to read CSV files and convert them to JSON files. And so it's one command. So I'm going to just print out and I'm going to use the JSON module and I say JSON. I don't know if it's JSON or just JSON. I say JSON. So JSON.dump, or dumps, and then inside parentheses we're going to say list. We're going to pass it a list and then we're going to use our CSV module. We're going to say CSV reader. So we're going to read a CSV file and then inside parentheses again, we're going to say open and then inside parentheses again, it's a lot of parentheses here. We're going to say our file, which is file.csv. And if I did everything correctly, there we go. This is that file in a JSON array, which is nice. So you can go through each item in an array and then you can call each section of the array from your application. So basically we're going to do this as a one-liner. It's basically the same two commands put into one-liner. So I'm going to control D to get out of Python. But what I can do is I can say Python dash C, which is say run this command. And then inside these parentheses, I am going to grab, I'm just copying and pasting for now to make it quicker. I'm going to say import CSV and JSON, semicolon meaning new Python command. I'm going to say print. I'm not going to type all this out again. I'm just going to copy and paste it. You don't want to watch me type it again. So now there we go. Now, again, I can use this command inside a shell script of some sort or call it really with any system commands. So even if you're writing something in C or PHP or Perl, which there's probably more efficient ways to do it if you're using these different languages. But this is a command that you know that you can call and convert very simply. And I have used this a few times anyway on web servers where I might be pulling CSV information maybe from a Google spreadsheet. And I want to convert it to a JSON format for easier use in my application right there. So I hope you did find this useful. It's probably just one of many ways. But it's just the quickest, simplest way I found in the shell. You would think there would be, if you know of an application, a standalone application that you can use in shell scripts that does this, let me know. That would be great. But Python is either on or very easily installed on any system and then installing modules is super simple on it. And I mean, you might be writing something in Python. This is great. But if you're just using a quick shell script or calling some sort of system command from another language, this is a quick and easy way to convert CSV files to JSON. I bet you could probably do it the other way. But for the most part, I prefer JSON over CSV, although CFC is just very simple to create, but a little bit more difficult to work with, in my opinion, than JSON format. I do thank you for watching. Please visit filmsbychrist.com. That's Chris with the K. There's a link in the description. You can go there or my Patreon page to support me. It's patreon.com. Also at my website, you can search through all my videos from both my channels or support me through PayPal. I do appreciate financial support if you're able to. If you're not able to but you like my videos, please give it a thumbs up, comment, and share. Thanks for watching and as always, I hope that you have a great day.