         
         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

        let language = settingsJSON[Settings.JSONKey.language].string ?? "en"
        let scaleY = settingsJSON[Settings.JSONKey.scaleY].string ?? "log"
        
        let enabled: [ShowPlugins] = settingsJSON[Settings.JSONKey.enable].arrayValue.flatMap {
            ShowPlugins(rawValue: $0.stringValue)
        }
        
        let thresholdsJSON = settingsJSON[Thresholds.JSONKey.thresholds]
        let thresholds = Thresholds(bgHigh: thresholdsJSON[Thresholds.JSONKey.bgHigh].doubleValue, bgLow: thresholdsJSON[Thresholds.JSONKey.bgLow].doubleValue, bgTargetBottom: thresholdsJSON[Thresholds.JSONKey.bgTargetBottom].doubleValue, bgTargetTop: thresholdsJSON[Thresholds.JSONKey.bgTargetTop].doubleValue)
        
        let alarmType = AlarmType(rawValue: settingsJSON[Settings.JSONKey.alarmType].stringValue) ?? .simple

            JSONKey.alarmUrgentLowMins: alarms.urgentLowMins,
            JSONKey.language: language,
            JSONKey.scaleY: scaleY,
            JSONKey.enable : enable.flatMap { $0.rawValue },
            JSONKey.alarmType: alarmType.description,
            JSONKey.heartbeat: heartbeat,
            JSONKey.baseURL: baseURL,
            JSONKey.thresholds: thresholds.encode()
        ]
    }
}

extension Thresholds: Encodable {
    struct JSONKey {
        static let bgHigh = "bgHigh"
        static let bgLow = "bgLow"
        static let bgTargetBottom = "bgTargetBottom"
