title: Swift 4 Codable; How to decode object with single root-level key
body: <p>I'm using the Swift 4 <code>Codable</code> protocol with JSON data. My data is formatted such that there is a single key at the root level with an object value containing the properties I need, such as:</p>
  
  <pre><code>{
    "user": {
      "id": 1,
      "username": "jdoe"
    }
  }
  </code></pre>
  
  <p>I have a <code>User</code> struct that can decode the <code>user</code> key:</p>
  
  <pre><code>struct User: Codable {
    let id: Int
    let username: String
  }
  </code></pre>
  
  <p>Since <code>id</code> and <code>username</code> are properties of <code>user</code>, not at the root level, I needed to make a wrapper type like so:</p>
  
  <pre><code>struct UserWrapper: Codable {
    let user: User
  }
  </code></pre>
  
  <p>I can then decode the JSON via the <code>UserWrapper</code>, and the <code>User</code> is decoded also. It seems like a lot of redundant code since I'll need an extra wrapper on every type I have. Is there a way to avoid this wrapper pattern or a more correct/elegant way of handling this situation?</p>