How do I parse a deeply nested JSON document that may have some missing or extra fields using Scala?
===

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.

I am currently using Jackson's Streaming API but the code required is difficult to understand and maintain. Instead, I'd like to use [Jerkson][1] to return an object representing the parsed JSON if possible.

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.

Say we have a Tweet:


    {
     "id": 100,
     "text": "Hello, world."
     "user": {
              "name": "Brett",
              "id": 200
             },
     "geo": {
             "lat": 10.5,
             "lng": 20.7 
            }
    }


Now, the Jerkson Case Class examples make a lot of sense when you only want to parse out, say, the ID:


    val tweet = """{...}"""
    case class Tweet(id: Long)
    val parsed = parse[Tweet](tweet)


But how do I deal with something like the Tweet above?

Some gotchas:

1. Some fields can be `null` or missing, for example "geo" above may be `null`, or one day they may drop a field and I don't want my parsing code to fail.
2. Some fields will be extra, or fields will be added and I want to be able to ignore them.

  [1]: https://github.com/codahale/jerkson/