title: python sort list of json by value
body: <p>I have a file consists of JSON, each a line, and want to sort the file by update_time reversed.</p>
  
  <p>sample JSON file:</p>
  
  <pre><code>{ "page": { "url": "url1", "update_time": "1415387875"}, "other_key": {} }
  { "page": { "url": "url2", "update_time": "1415381963"}, "other_key": {} }
  { "page": { "url": "url3", "update_time": "1415384938"}, "other_key": {} }
  </code></pre>
  
  <p>want output:</p>
  
  <pre><code>{ "page": { "url": "url1", "update_time": "1415387875"}, "other_key": {} }
  { "page": { "url": "url3", "update_time": "1415384938"}, "other_key": {} }
  { "page": { "url": "url2", "update_time": "1415381963"}, "other_key": {} }
  </code></pre>
  
  <p>my code:</p>
  
  <pre><code>#!/bin/env python
  #coding: utf8
  
  import sys
  import os
  import json
  import operator
  
  #load json from file
  lines = []
  while True:
      line = sys.stdin.readline()
      if not line: break
      line = line.strip()
      json_obj = json.loads(line)
      lines.append(json_obj)
  
  #sort json
  lines = sorted(lines, key=lambda k: k['page']['update_time'], reverse=True)
  
  #output result
  for line in lines:
      print line
  </code></pre>
  
  <p>The code works fine with sample JSON file, but if a JSON has no 'update_time', it will raise KeyError exception. Are there non-exception ways to do this?</p>