Just a cute pic of me
by Mike McKee
Data

Using Python to Find a JSON File's Hierarchy

66 Days of Math and Programming -- Day 37

There ain’t no breaks in the Dorky World of Data.

Now that I’ve finished my most recent project (although I still have to do the write-up), I’m on the market for something new.

And this time around, I’ve decided to do something with Python and SQL.

And guess what the crazy data dork in me decided…

I decided to take the JSON file with data from my Spotify playlist and turn the whole thing into a few SQL tables.

But here’s the crazy part…

The file has 197,051 lines of data.

Nearly 200,000 lines I’ll have to work with.

That may not seem like a challenge to you, but it’s gonna be a lot for me. I guess the bright side of this mini-project is that I’ll be busy for a while – but not too busy for this dorky blog.

Anyway, this project is like building a house.

You can’t build it without setting a foundation first.

And my foundation comes in the form of understanding the JSON file’s hierarchy. If I don’t understand how keys and values relate to each other, I’ll never be able to create SQL tables.

That’s why my first adventure down this dorky path consisted of writing a recursive Python function to find my JSON file’s hierarchy.

If you want to see how I did it, check out my code below.

Share your thoughts and let me know if this seems like something you could do too.

python function to traverse a JSON file