         dict[JSONKey.serverTime] = serverTime
         dict[JSONKey.careportalEnabled] = careportalEnabled
         dict[JSONKey.boluscalcEnabled] = boluscalcEnabled
-        dict[JSONKey.settings] = settings?.description
+        dict[JSONKey.settings] = settings?.encode()
         dict[JSONKey.head] = head
         dict[JSONKey.version] = version
         dict[JSONKey.name] = name
-        
+
         return dict
+    }
+   func decode(dict: [String: AnyObject]) -> ServerConfiguration? {
+        
+    guard let status = dict[JSONKey.status] as? String, apiEnabled = dict[JSONKey.apiEnabled] as? Bool, serverTime = dict[JSONKey.serverTime] as? String, careportalEnabled = dict[JSONKey.careportalEnabled] as? Bool, boluscalcEnabled = dict[JSONKey.boluscalcEnabled] as? Bool, head = dict[JSONKey.head] as? String, version = dict[JSONKey.version] as? String, name = dict[JSONKey.name] as? String else {
+        return nil
+    }
+    
+    var settings: Settings?
+
+    if let settingsDict = dict[JSONKey.settings] {
+        settings = nil
+    }
+
+    var config = ServerConfiguration(status: status, version: version, name: name, serverTime: serverTime, api: apiEnabled, carePortal: careportalEnabled, boluscalc: boluscalcEnabled, settings: settings, head: head)
+    
+    
+    return config
     }
 }
 

        static let alarmType = "alarmType"
        static let heartbeat = "heartbeat"
        static let baseURL = "baseURL"
        
    }
    func encode() -> [String : AnyObject] {

        
        let mbgs = json[JSONPropertyKey.mbgs]
        print("mbgs count: \(mbgs.count)")
        
        for (_, subJson) in mbgs {
            if let deviceString = subJson[MeteredGlucoseValue.JSONKey.device].string, mills = subJson[MeteredGlucoseValue.JSONKey.mills].double, mgdl = subJson[MeteredGlucoseValue.JSONKey.mgdl].double {
                let device = Device(rawValue: deviceString) ?? Device.Unknown
