

JSON (pronounced “JAY-sawn” or “Jason”-it doesn’t matter how because either way people will say you’re pronouncing it wrong) is a format that stores information as JavaScript source code in plaintext files. Python’s csv module makes it easy to parse CSV files. But Python also comes with the special csv and json modules, each providing functions to help you work with these file formats.ĬSV stands for “comma-separated values,” and CSV files are simplified spreadsheets stored as plaintext files. You can view them in a text editor, such as Mu. CSV and JSON files, on the other hand, are just plaintext files. These files were in a binary format, which required special Python modules to access their data. On the other hand, JSON files can have much more complex structures than CSV files, so a direct conversion is not always possible and will require us to rework our structure of the file concerned.In Chapter 15, you learned how to extract text from PDF and Word documents. SummaryĪs we have seen, it may be easy to convert a Json file to a CSV file. Of course it’s possible to get all the JSON file data. To retrieve the header we need to use the keys() function which allows us to get the keys of each “ Name” element of our JSON file. We were able to export the different names of the Pokémon in the CSV. Here is an example with the pokedex.json file :Ĭsvwriter.writerow(data.keys()) To read a JSON file we can use the read_json function. Indeed a lot of python API returns as a result of JSON and with pandas it is very easy to exploit this data directly. Pandas is a python library that allows to easily manipulate data to be analyzed.
