title: SwiftUI Parsing and displaying values form a JSON call
body: <p>End Goal: To have a macOS app to monitor the temperature values from my bluetooth bbq probe, refreshing the data every X mins to keep an eye on it whilst at my desk.</p>
  <p>macOS App</p>
  <p>JSON structure</p>
  <pre><code>{
      &quot;status&quot;: &quot;OK&quot;,
      &quot;statusCode&quot;: 200,
      &quot;data&quot;: {
          &quot;devices&quot;: [
              {
                  &quot;id&quot;: &quot;xxxxxxxxxxxxxxxxx&quot;,
                  &quot;temperature&quot;: {
                      &quot;internal&quot;: 25.8,
                      &quot;ambient&quot;: 25.8
                  },
                  &quot;cook&quot;: {
                      &quot;id&quot;: &quot;xxxxxxxxxxxxxxxxx&quot;,
                      &quot;name&quot;: &quot;Whole Chicken&quot;,
                      &quot;state&quot;: &quot;Configured&quot;,
                      &quot;temperature&quot;: {
                          &quot;target&quot;: 74,
                          &quot;peak&quot;: 25.8
                      },
                      &quot;time&quot;: {
                          &quot;elapsed&quot;: 232,
                          &quot;remaining&quot;: -1
                      }
                  },
                  &quot;updated_at&quot;: 1622816968 
              }
          ]
      },
      &quot;meta&quot;: {}
  }
  </code></pre>
  <p>ContentView.swift</p>
  <pre><code>import SwiftUI
  
  struct ContentView: View {
  
      @State var probeData = [Meater]()
  
  
      var body: some View {
          
          VStack {
              
                HStack{
              
              List{
                  Text(&quot;Current Cook: \(probeData.Devices.cook.name)&quot;)
                      .font(.system(size: 20))
                      .fontWeight(.light)
                      .foregroundColor(.primary)
                  
                  Text(&quot;Target Temparature: \(probeData.Devices.cook.temperature.target) as String&quot;)
                      .font(.callout)
                      .fontWeight(.light)
                      .foregroundColor(.primary)
                  Text(&quot;Internal Temperature: \(probeData.Devices.cook.temperature.internal) as String&quot;)
                      .font(.callout)
                      .fontWeight(.light)
                      .foregroundColor(.primary)   
                  Text(&quot;Ambient Temperature: \(probeData.Devices.cook.temperature.ambient) as String&quot;)
                      .font(.callout)
                          .fontWeight(.light)
                          .foregroundColor(.primary)                      
              }
  
  Text(&quot;Time Elapsed: \(probeData.Devices.cook.time.elapsed)&quot;)
                          .font(.system(size: 20))
                          .fontWeight(.light)
                          .foregroundColor(.primary)
                      
                      Text(&quot;Time Remaining: \(probeData.Devices.cook.time.remaining)&quot;)
                          .font(.callout)
                          .fontWeight(.light)
                          .foregroundColor(.primary)
            
          }
          }
      }
  
      //MARK: - Web Service
  
      func loadData() {
          
          let url = URL(string: &quot;https://xxxxxxxx&quot;)
                 var request = URLRequest(url: url!)
                 request.httpMethod = &quot;GET&quot;
              request.addValue(&quot;Bearer xxxxxxxxxxxxxx&quot;, forHTTPHeaderField: &quot;Authorization&quot;)
  
                 let task = URLSession.shared.dataTask(with: request) { data, response, error in
                 
                  do {
                      if let d = data {
                          let decodedLists = try JSONDecoder().decode(Meater.self, from: d)
  
                         
                          DispatchQueue.main.async {
  
                              self.probeData = [decodedLists]
                              print(probeData)
                          }
                      }else {
                          print(&quot;No Data&quot;)
                      }
                  }catch DecodingError.keyNotFound(let key, let context) {
                      Swift.print(&quot;could not find key \(key) in JSON: \(context.debugDescription)&quot;)
                  } catch DecodingError.valueNotFound(let type, let context) {
                      Swift.print(&quot;could not find type \(type) in JSON: \(context.debugDescription)&quot;)
                  } catch DecodingError.typeMismatch(let type, let context) {
                      Swift.print(&quot;type mismatch for type \(type) in JSON: \(context.debugDescription)&quot;)
                  } catch DecodingError.dataCorrupted(let context) {
                      Swift.print(&quot;data found to be corrupted in JSON: \(context.debugDescription)&quot;)
                  } catch let error as NSError {
                      NSLog(&quot;Error in read(from:ofType:) domain= \(error.domain), description= \(error.localizedDescription)&quot;)
                  }
                 }
                 task.resume()
  
      }
  
  }
  
  struct ContentView_Previews: PreviewProvider {
      static var previews: some View {
              ContentView()
      }
  }
  
  // MARK: - Data Model
  
  struct Meater: Codable {
    struct Data: Codable {
      struct Devices: Codable {
        struct Temperature: Codable {
          let `internal`: Double
          let ambient: Double
        }
  
        struct Cook: Codable {
          struct Temperature: Codable {
            let target: Int
            let peak: Double
          }
  
          struct Time: Codable {
            let elapsed: Int
            let remaining: Int
          }
  
          let id: String
          let name: String
          let state: String
          let temperature: Temperature
          let time: Time
        }
  
        let id: String
        let temperature: Temperature
        let cook: Cook
        let updatedAt: Date
  
        private enum CodingKeys: String, CodingKey {
          case id
          case temperature
          case cook
          case updatedAt = &quot;updated_at&quot;
        }
      }
  
      let devices: [Devices]
    }
  
    struct Meta: Codable {
    }
  
    let status: String
    let statusCode: Int
    let data: Data
    let meta: Meta
  }
  </code></pre>
  <p>Debugger seems to print the correct info from probeData but can't seem to work out why the values aren't displaying.</p>
  <p>any pointers in the right direction would be appreciated. Thank you</p>