Login and get coding
In this Bite we are going to convert some Warcraft Mount JSON data to
Here are the steps to take:
Load the JSON into a
dict, look for mounts > collected.
If invalid JSON (yes, real developer life!), print "exception caught" (defined in the
EXCEPTIONconstant) 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
pandasbut 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.