title: Mapping a JSON object to a Swift class/struct
body: <p>I need to "replicate" an entiry which is returned from a remote web API service in JSON. It looks like this:</p>
  
  <pre><code>{
    "field1": "some_id",
    "entity_name" = "Entity1"
    "field2": "some name",
    "details1": [{
      "field1": 11,
      "field2": "some value",
      "data": {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3",
        // any other, unknown at compile time keys
      }
    }],
    "details2": {
      "field1": 13,
      "field2": "some value2"
    }
  }
  </code></pre>
  
  <p>Here's my attempt:</p>
  
  <pre><code>struct Entity1 {
    struct Details1 {
      let field1: UInt32
      let field2: String
      let data: [String: String]
    }
  
    struct Details2 {
      let field1: UInt32
      let field2: String
    }
  
    let field1: String
    static let entityName = "Entity1"
    let field2: String
    let details1: [Details1]
    let details2: Details2 
  }
  </code></pre>
  
  <ol>
  <li>Is it a good idea to use structs instead of classes for such a goal
  as mine? </li>
  <li>Can I anyhow define a nested struct or a class, say
  Details1 and create a variable of it at the same time? </li>
  </ol>
  
  <p>Like this:</p>
  
  <pre><code>//doesn't compile 
  struct Entity1 {
    let details1: [Details1 { 
    let field1: UInt32
    let field2: String
    let data: [String: String]
  }]
  </code></pre>