                         dictionary[key] = value
                     }
 
-                    let token = tokens[next]
-                    if case .EndObject = token {
-                        next++
-                        return .Dictionary(dictionary)
-                    }
-
-                    guard let _ = parseComma() else {
-                        print("Expect comma")
-                        break
+                    if let token = tokens[safe: next] {
+
+                        if token.isEndObject {
+                            next++
+                            return .Dictionary(dictionary)
+
+                        } else {
+                            guard let _ = parseComma() else {
+                                print("Expect comma")
+                                break
+                            }
+
+                            guard let nextToken = tokens[safe: next] where !nextToken.isEndObject else {
+                                print("Invalid JSON, expect more key : value")
+                                break
+                            }
+                        }
                     }
                 }
             }

    var isNull: Swift.Bool {
        switch self {
        case .Null:
            return true
        default:
            return false

        }).joinWithSeparator("")
    }
}

private extension Array {

    subscript (safe index: Int) -> Element? {
        return index >= 0 && index < count ? self[index] : nil
    }
}
