title: Parsing JSON using try and except
body: <p>I am probably able to solve this myself if I had the time to investigate. I've been trying different things but I can't get it to work! I am doing my master in Marketing, and we are expected to be able to code in Python very basically to parse a dataset (json) into an organised text file that can be used for further analysis.</p>
  
  <p>We have a dataset with a lot of missing values. What I want to be parsed is this: artist, mbid (music brainz artist id), event data, venue name, city.</p>
  
  <p>This is (part of) the script I have written for that:</p>
  
  <pre><code>for event in setlists:
      eventdate = event.get(u'@eventDate')
      venuename = event.get(u'venue').get(u'@name')
      mbid = event.get(u'artist').get(u'@mbid')
      artistname = event.get(u'artist').get(u'@name')
      city = event.get(u'venue').get(u'city').get(u'@name')
  
      f = open(parse_file, 'a')
      f.write(artistname+'\t'+mbid+'\t'+eventdate+'\t'+venuename+'\t'+city+'\n')
      f.close()
  </code></pre>
  
  <p>This script works like a charm, except for that it leaves out entries for which there are missing values, e.g. no city.</p>
  
  <p>I want it to report it to a line of text anyway, and print "missing" for the info that is missing.</p>
  
  <p>I can't get it to work and I don't know where to start either. I tried things like this:</p>
  
  <pre><code>f = open(parse_file, 'a')
  try: f.write(artistname) except: continue try: f.write(mbid) except:     continue...
  f.close()
  </code></pre>
  
  <p>Every line in the parsed file should like like this:</p>
  
  <p>artistname mbid eventdate venuename location</p>
  
  <p>I did try to put everything on different lines but then the problem was the output was vertically and not horizontally for each event.</p>