title: Scala - Dealing with null JSON objects
body: <p>So I'm parsing JSON in scala. I've got an object which occasionally is null. How should I deal with this?</p>
  
  <p>I would think that <code>if (json.get("object") != null) {...}</code> would work, but it doesn't.</p>
  
  <p>This is code I've been experimenting with:</p>
  
  <pre><code>import org.json._
  
  val json: JSONObject = new JSONObject("{\"object\": null}")
  
  if (json.get("object") != null) {
      println("The object is not null") //This like is executed
  } else {
      println("the object is null") This line is not executed
  }
  
  println(json.getString("object")) //This line returns "org.json.JSONException: JSONObject["object"] not a string."
  </code></pre>
  
  <p>So how can I avoid null pointer exceptions when parsing JSON?</p>