title: Writing a SwiftUI model to read from a JSON file with Arrays
body: <p>I'm pretty green when it comes to working with data flow but I'm trying to force myself through the exercise of building an application to learn it. I'm struggling with how to write my model to correctly reference nested keys in a JSON file.</p>
  
  <p>The JSON looks like this:</p>
  
  <pre><code>[{
      "id": 1001,
      "first_name": "Jimmy",
      "last_name": "Simms",
      "cities": [{
              "name": "New York City",
              "towns": [{
                      "name": "Brooklyn"
                  },
                  {
                      "name": "Manhatten"
                  }
              ]
          },
          {
              "name": "Tokyo",
              "towns": [{
                      "name": "Churo"
                  },
                  {
                      "name": "Riponggi"
                  }
              ]
          }
      ]
  }]
  </code></pre>
  
  <p>What I'm unsure how to do is write a model that lets me target nested elements inside the arrays. Broadly speaking, I'm wondering how you might right a SwiftUI model for this JSON set.</p>
  
  <p>This was kind of my stab in the dark at it:</p>
  
  <pre><code>import SwiftUI
  
  struct MyDataModel: Identifiable {
      var id: Int
      var first_name: String
      var last_name: String
      var cities: Array&lt;Any&gt;
      var cities.name: String
      var cities.towns: Array&lt;Any&gt;
      var cities.towns.name: String
  }
  </code></pre>
  
  <p>But my syntax for accessing the nested arrays "Cities" and then the second level "Towns" is just made up and I can find a reference for how to access nested key's like this? Any help would be much appreciated.</p>