Handy converting of data in CSV into JSON
Currently i'm working on my fabricator.js library , which is basically a javascript analog of my already existing scala fabricator library. The reason i'm doing this is that i would like to use my fake data generator in node cli tool and also i would like to make a Chrome extension that would help manual testers to get random "close to reality looking" fake data. On one of the steps i faced with an issue of extracting table with data on html page and converting it into JSON file. The table looked like this :
If you select it and paste into the Spreadsheet, then you'll get a nice table with your data, but how can you convert it into JSON? Well, in my previous posts i already said that for small automation tasks i really love Python. As i expected, after 5 minutes of goodling i came to this solution :
- Save spreadsheet with data as csv file
- Open your favorite IDE or text editor and run this file :
This script contains data that is specific to my use case, but you can easily adjust it for you. Here's how :
- Modify
csvfile
andjsonfile
variables with a path to your csv file and to where you want to save your json file - Modify
fieldnames
array with column names that you have in your csv file
As a result, you'll have a nicely formatted json file with data that you need :
Happy coding.