title: Swift get data from local JSON file and load into Tableview
body: <p>My scenario, I am trying to load local <code>JSON</code> file data Into <code>tableview</code>. Here, I would like to know which is proper method for referring local JSON file and how to use it simply using <code>struct</code> and <code>codable</code> to load Into Tableview.</p>
  
  <p>I would like to know below details and sample code with highly professional method.</p>
  
  <p>How to call my JSON file in a proper way and need to get the data from JSON file with help of struct and Codable to load in tableview?</p>
  
  <p>My JSON File </p>
  
  <pre><code>[{
      "flag": "usa.png",
      "country": "USA",
      "countryName": "United States"
  }, {
      "flag": "india.png",
      "country": "IND",
      "countryName": "India"
  }, {
      "flag": "uk.png",
      "country": "UK",
      "countryName": "United Kingdom"
  }]
  </code></pre>
  
  <p>My Code </p>
  
  <pre><code>if let path = Bundle.main.path(forResource: "sample", ofType: "json") {
      do {
            let data = try Data(contentsOf: URL(fileURLWithPath: path), options: .mappedIfSafe)
            let jsonResult = try JSONSerialization.jsonObject(with: data, options: .mutableLeaves)
            if let jsonResult = jsonResult as? Dictionary&lt;String, AnyObject&gt;, let person = jsonResult["person"] as? [Any] {
            }
        } catch {
        }
  }
  </code></pre>