title: How to get get data from a json file in a Widget bundle in Swift?
body: <p>I have a json file like this :</p>
  <pre><code>[
    {
      &quot;car&quot; : &quot;yellow&quot;,
      &quot;tires&quot; : &quot;black&quot;
    },
    {
      &quot;car&quot; : &quot;blue&quot;,
      &quot;tires&quot; : &quot;brown&quot;
    }
  ]
  </code></pre>
  <p>How do I get the data into the widget bundle? <br>
  (having already done the CarTypes stuct) <br>
  I have tried to use :</p>
  <pre><code>
  var weeks: [CarTypes] = load(&quot;cars.json&quot;)
  
  func load&lt;T: Decodable&gt;(_ filename: String) -&gt; T {
      let data: Data
  
      guard let file = Bundle.main.url(forResource: filename, withExtension: nil)
      else {
          fatalError(&quot;Couldn't find \(filename) in main bundle.&quot;)
      }
  
      do {
          data = try Data(contentsOf: file)
      } catch {
          fatalError(&quot;Couldn't load \(filename) from main bundle:\n\(error)&quot;)
      }
  
      do {
          let decoder = JSONDecoder()
          return try decoder.decode(T.self, from: data)
      } catch {
          fatalError(&quot;Couldn't parse \(filename) as \(T.self):\n\(error)&quot;)
      }
  }
  
  </code></pre>
  <p>But it says that file is not in the main bundle i.e &quot;Couldn't find cars.json in main bundle.&quot;</p>