Use switch for Swift 1.1 compatibility
Use JSON enum and function composition