 Hello, and welcome from this video by Films by Chris. We've been looking at in the last couple videos converting spreadsheets to CSV files Now we're gonna look at converting CSV files to JSON files, which is a very useful of text format that is a little you know Better arranged for a lot of things than a CSV file is But between the two I use comma-separated value files and JSON files both Equally, you know if it's plain text it's better than than a binary blob for most things I do anyway So anyway, here we go. You can see that I've got a couple of spreadsheets here. They're all Identical and we looked at converting them to CSV files, but to convert it from a CSV file to a JSON file There's one thing we have to make sure our CSV file has And then also we need a script that will convert it now I have looked through the repositories many times I've not been able to find a program that converts from CSV to JSON So if I was to for example use aptitude I could search for CSV Which will give me a list of things and I can quickly grep through that list for JSON Nothing comes up and I've tried the other way where I've searched for JSON and then I've grep which Gives you a bunch of things and then I've grep that for CSV And again nothing so there might be something in there, but I don't see anything by name or quick description that Indicates it's for converting the CSV to a JSON file And then I looked online and I saw a lot of different scripts that people have written most of them did not work I eventually found one that worked mostly and then I had to make a Certain CSV files. I had to have certain characters or something and then they're throwing it off So I made a few tweaks to this if I remember correctly. I don't remember exactly Oh, what that I that I changed CSV to JSON. It's a Python script. Actually, let's use less So this is the file here. It's not very long at all It does import a couple of modules here CSV module and the JSON module that you I don't know if those are installed by the fault of Python I don't remember installing anything particular to get this to work Once you have that you can just run that command And if she wants you have it I've put it in my local bin folder But you put it wherever you put your executable scripts if you just run it once you make it execute Well, and I'll put a link to that script in the description It does give you the usage if you don't give it anything. So it's very simple you run the script input file name Output file name and you have an option here of pretty or or dump and I'm thinking that's just I always just put pretty I think without that it doesn't just format it with indentations and stuff like that But again, we can't just if we were just take this so let's see we've got our spreadsheets here Let's do SS convert and we'll give it the people ODS we did this in a previous video and we'll do the output people dot CSV And now I can cat out our people at CSV file and if I was to use CSV to whoops, let's clear the screen here to JSON input file people that CSV and I was to do the output file of people dot JSON and I'll do format Pretty we'll do that and then I can cat out our people dot JSON file and you can see we have nicely looking JSON here but it looks funny our Field names here carry Yolanda Gainesville Gainesville. What is that? Well, what this script does is it takes the first line of the CSV file and it uses that for its tags So you know what each? Column is for so if that didn't make any sense because I feel like I didn't explain it very well I'll show you what I mean. So I'll remove that JSON file. We just created and I will also remove our people that CSV file and I'll just use Libre office Bray office and our people I'll use our open document spreadsheet So what we need to do here is we have this column which is an ID column and then we got last name first name address We got city zip birthdate. This is their phone number. We have their Area code and their phone number. So what we need to do here is just right-click here and say Insert row above and then here we just need to label these columns So I'll just call this one ID and you call them whatever you want. I'll call this one Actually, that's the last name L name. I'll call this F name. I'll call this address. I'll call this city zip Dob date of birth Area code and Phone now that I have that again, we're in Libre office. I can just go save as and I can choose CSV text save Yes, I want to do CSV. We'll leave these as the default and there we go Now we can close this out and now we can cat out our people dot CSV file And if we were to head that out, you'll see that our people dot CSV file The first line has that information there now if we run our command here CSV to JSON dash I our input file dash O our JSON output file pretty now We have that we've generated we can do people dot JSON You can see now here our We have our city. We have our zip our date of birth L name phone number, which now everyone had a phone number F name for first name address ID and Area code again, and then I'm assuming that there's just some empty fields and that's why it's generating this The the order here does not matter because with JSON you're gonna call I want the zip code I want the do be I want the phone number and there you go You have yourself a it's in a JSON format. It's actually in a JSON array as you can see the bracket here So each one of these items is an item in an array or an object in an array With its current attributes, so that is it again I'll put a link in the description to the people that CSV file and I'll also give you a link to The Python file I wish I can give credit to who created it But I've had this script for a long time. It's something I found in a forum a Year or two ago. I'm sure if you search parts of the script. You'll probably you'll find the original creator I do thank you for watching. Please visit films by Chris calm. That's Chris the K There's a link in the description as always. I hope that you have a great day