GH avatar Bite 227. Convert Warcraft json data to csv

In this Bite we are going to convert some Warcraft Mount JSON data to csv.

Here are the steps to take:

  • Complete convert_to_csv that receives a json_file, the files used for this Bite are hosted here, here and here - basically small subsets of the linked gist above.

    Load the JSON into a dict, look for mounts > collected.

    If invalid JSON (yes, real developer life!), print "exception caught" (defined in the EXCEPTION constant) and reraise the exception.

    If good data write it to a csv file in /tmp, for example:

    $ cat /tmp/mount1.csv
    creatureId,icon,isAquatic,isFlying,isGround,isJumping,itemId,name,qualityId,spellId
    32158,ability_mount_drake_blue,False,True,True,False,44178,Albino Drake,4,60025
    63502,ability_mount_hordescorpionamber,True,False,True,True,85262,Amber Scorpion,4,123886
    24487,ability_mount_warhippogryph,False,True,True,False,45725,Argent Hippogryph,4,232412
    

By the way, yes, you can do this with pandas but for this Bite we are assuming you don't have access to this library. It's good to learn the standard library!

Have fun and code more Python! For more JSON and CSV, check out our data formats learning path.

Login and get coding
go back Intermediate level
Bitecoin 3X

18 out of 20 users completed this Bite.
Will you be Pythonista #19 to crack this Bite?
Resolution time: ~48 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 6.0 on a 1-10 difficulty scale.
» Up for a challenge? 💪

We use Python 3.7