Convert warcraft json data to csv
Level: Intermediate (score: 3)
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 ajson_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.