title: Swift 4 Decodable - No value associated with key CodingKeys
body: <p>I'm decoding a JSON response in my Swift App, and the code used to work till it decided to stop working.</p>
  <p>this is my json reposnse</p>
  <pre><code>{
      &quot;foods&quot;: [
          {
              &quot;food_name&quot;: &quot;Milk Chocolate&quot;,
              &quot;brand_name&quot;: &quot;Snickers&quot;,
              &quot;serving_weight_grams&quot;: 41.7,
              &quot;nf_calories&quot;: 212.3,
              &quot;nf_total_fat&quot;: 11.6,
              &quot;nf_saturated_fat&quot;: 4,
              &quot;nf_total_carbohydrate&quot;: 22.7,
              &quot;nf_protein&quot;: 3.9
          }
      ]
  }
  </code></pre>
  <p>And this is the code to decode my json</p>
  <pre><code>let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
          guard let data = data else { return }
          
          print(String(data: data, encoding: .utf8)!)
          do {
              //Decode dataResponse received from a network request
              let decoder = JSONDecoder()
              let foods = try decoder.decode(JSONFoods.self, from: data) //Decode JSON Response Data
              
              self.jsonfood = foods.JSONFood[0]
              print(self.jsonfood!)
              
          } catch let parsingError {
              print(&quot;Error&quot;, parsingError)
          }
          
      }
      task.resume()
  </code></pre>
  <p>And my Structs are</p>
  <pre><code>struct JSONFoods: Decodable {
  var JSONFood: [JSONFood]    
  }
  
  struct JSONFood: Decodable{
  var food_name: String
  var brand_name: String
  var nf_calories: Int
  var nf_protein: Int
  var nf_total_fat: Int
  var nf_total_carbohydrate: Int
  var serving_weight_grams: Int
  }
  </code></pre>
  <p>And the error message I get is this</p>
  <blockquote>
  <p>keyNotFound(CodingKeys(stringValue: &quot;JSONFood&quot;, intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: &quot;No value associated with key CodingKeys(stringValue: &quot;JSONFood&quot;, intValue: nil) (&quot;JSONFood&quot;).&quot;, underlyingError: nil))</p>
  </blockquote>
  <p>And if i get replace decode(<strong>JSONFoods</strong>.self, from: data) with decode(<strong>JSONFood</strong>.self, from: data)
  I get this error message</p>
  <blockquote>
  <p>keyNotFound(CodingKeys(stringValue: &quot;food_name&quot;, intValue: nil), Swift.DecodingError.Context(codingPath: [], debugDescription: &quot;No value associated with key CodingKeys(stringValue: &quot;food_name&quot;, intValue: nil) (&quot;food_name&quot;).&quot;, underlyingError: nil))</p>
  </blockquote>
  <p>I searched everywhere with no luck, any help is very appreciated</p>