         
         let cals = json[JSONPropertyKey.cals]
         print("cals count: \(cals.count)")
-
+        
         for (_, subJson) in cals {
             if let slope = subJson[Calibration.JSONKey.slope].double, intercept = subJson[Calibration.JSONKey.intercept].double, scale = subJson[Calibration.JSONKey.scale].double, mills = subJson[Calibration.JSONKey.mills].double {
                 let calibration = Calibration(slope: slope, intercept: intercept, scale: scale, milliseconds: mills)

        
        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

            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"
