title: How to decode JSON array as property of struct with JSONDecoder
body: <p>I had data struct like this</p>
  <pre><code>{
      &quot;version&quot;: 1,
      &quot;profile&quot;: [
          {
              &quot;type&quot;: &quot;name&quot;,
              &quot;value&quot;: &quot;Hellow&quot;
          },
          {
              &quot;type&quot;: &quot;email&quot;,
              &quot;value&quot;: &quot;1@a.com&quot;
          },
      ]
  }
  </code></pre>
  <p>Now I could decode it like this</p>
  <pre><code>struct Profile: Decodable {
      let version: Int
      let name: String
      let email: String
      struct Item: Decodable {
          let type: String
          let value: String
      }
  
      init(from decoder: Decoder) throws {
          let container = try decoder.container(keyedBy: CodingKeys.self)
          version = try container.decode(Int.self, forKey: .version)
          let items = try container.decode([Item].self, forKey: .data)
          name = items.first{$0.type == &quot;name&quot;}!.value
          email = items.first{$0.type == &quot;email&quot;}!.value
      }
  }
  </code></pre>
  <p>Does there are any way to update Profile without rewrite init(from)?</p>
  <p><strong>Update</strong><br />
  <code>@dynamicMemberLookup</code> can use like mapping function.
  But it will lose autocomplete.</p>
  <pre><code>@dynamicMemberLookup
  struct Profile: Decodable {
      let version: Int
      
      struct Item: Decodable {
          let type: Keys
          let value: String
      }
      let profile: [Item]
      
      enum Keys: String, Decodable, ExpressibleByStringLiteral {
          case name
          case email
          case undefined
          
          init(stringLiteral: String) {
              self = Keys(rawValue: stringLiteral) ?? .undefined
          }
      }
      
      subscript(dynamicMember member: Keys) -&gt; String {
          return profile.first{$0.type == member}?.value ?? &quot;undefined&quot;
      }
  }
  </code></pre>