title: How do I parse a deeply nested JSON document that may have some missing or extra fields using Scala?
body: <p>I have read other Scala JSON parsing questions but they all seem to assume a very basic document that is not deeply nested or of mixed types. Or they assume you know all of the members of the document or that some will never be missing.</p>
  
  <p>I am currently using Jackson's Streaming API but the code required is difficult to understand and maintain. Instead, I'd like to use <a href="https://github.com/codahale/jerkson/" rel="nofollow">Jerkson</a> to return an object representing the parsed JSON if possible.</p>
  
  <p>Basically: I'd like to replicate the JSON parsing functionality that's so familiar to me in dynamic languages. I realize that's probably very wrong, and so I'm here to be educated.</p>
  
  <p>Say we have a Tweet:</p>
  
  <pre><code>{
   "id": 100,
   "text": "Hello, world."
   "user": {
            "name": "Brett",
            "id": 200
           },
   "geo": {
           "lat": 10.5,
           "lng": 20.7 
          }
  }
  </code></pre>
  
  <p>Now, the Jerkson Case Class examples make a lot of sense when you only want to parse out, say, the ID:</p>
  
  <pre><code>val tweet = """{...}"""
  case class Tweet(id: Long)
  val parsed = parse[Tweet](tweet)
  </code></pre>
  
  <p>But how do I deal with something like the Tweet above?</p>
  
  <p>Some gotchas:</p>
  
  <ol>
  <li>Some fields can be <code>null</code> or missing, for example "geo" above may be <code>null</code>, or one day they may drop a field and I don't want my parsing code to fail.</li>
  <li>Some fields will be extra, or fields will be added and I want to be able to ignore them.</li>
  </ol>