title: Swift 4 JSONDecoder Complex Data Missing Key
body: <p>I have been struggling with this for over a day now and Im not sure why I keep getting the Missing Key error when I clearly defined the key in my struct. Your help would be really appreciated. Please help clear up my confusion on how to decode nested types in JSON.</p>
  
  <p>I am trying to parse the following JSON response but keep getting the Missing Key error message when I run my app.  Below is the message I get back from the service.</p>
  
  <p>Here is the JSON resonse</p>
  
  <pre><code>{
      UserInfo =     {
          ApplicationArea =         {
              CreationDateTime = "2018-02-11 21:34:40.646000";
              MfgCode = PSUN;
              Sender = DM;
          };
          ServiceStatus =         {
              StatusCode = 0;
              StatusDescription = Success;
              System = "Product Info";
          };
          UserInfoDataArea =         {
              Email = "john@example.com";
              Locale = "en_US";
              UserId = 3;
              UserName = jdoe;
          };
      };
  }
  </code></pre>
  
  <p>Here is the ERROR</p>
  
  <pre><code>    Missing Key: applicationArea 
  Debug description: No value associated with key applicationArea ("ApplicationArea").
  </code></pre>
  
  <p>Below is my struct code for getting the request and to decode the response.</p>
  
  <pre><code>    struct UserInfo:Codable {
  
          struct ApplicationArea:Codable {
              let creationDateTime: String
              let mfgCode: String
              let sender: String
  
              private enum CodingKeys: String, CodingKey {
                  case creationDateTime = "CreationDateTime"
                  case mfgCode = "MfgCode"
                  case sender = "Sender"
              }
          }
          let applicationArea: ApplicationArea
  
          enum CodingKeys: String, CodingKey {
              case applicationArea = "ApplicationArea"
          }    
      }
  </code></pre>
  
  <p>Code for creating the request</p>
  
  <pre><code>let apiMethod = HTTPMethod.post
  
  Alamofire.request(
      loginURL!,
      method: apiMethod,
      parameters: params,
      encoding: URLEncoding.default,
      headers: header)
      .responseJSON { (response) -&gt; Void in
  
          switch response.result {
          case .success:
  
              print(response.result.value)
  
              let result = response.data
              do {
                  let decoder = JSONDecoder()
                  let userDetails = try decoder.decode(UserInfo.self, from: result!)
                      print("Response \(userDetails)")
              } catch DecodingError.keyNotFound(let key, let context) {
                  print("Missing Key: \(key)")
                  print("Debug description: \(context.debugDescription)")
              } catch {
                  print("Error \(error.localizedDescription)")
              }
  
          case .failure(let error):
              print("Error \(error)")
          }
  }
  </code></pre>