Modupe Afolabi-Jombo’s Post

I mentioned last week that I recently discovered that in Python, we can read and write files without using pandas. I also spoke briefly about the different file modes that can be used to achieve this and shared a link to the code.(Link to post: https://lnkd.in/dVNYXsAf) In that post, I worked with a CSV file. However, this time around, I wrote to and read from a JSON file still without using pandas. Here is a brief step-by-step explanation of how I did it: ✔️ First, I imported the necessary libraries: Faker (for generating dummy data) and json (for writing data to the JSON file). ✔️Then, I created a few variables for different purposes: => output –> to create a new JSON file and open a connection for writing the generated data. => fake –> to hold the records generated by the Faker library. => alldata –> an empty dictionary that temporarily stores the dummy data before inserting it into a record list. ✔️After creating these variables, I used a loop to generate and insert data from the fake variable into the alldata dictionary. ✔️Finally, I used json.dump to move the data from alldata into the output file and closed the connection. Here is a snapshot of the code and a link to the full script where I wrote and read from a JSON file. Link to full script: https://lnkd.in/dG88jyAa #DataEngineering #Python #PythonModes #JSON #JSONFiles #github

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories