title: Swift JSON decode & encode with different results
body: <p>)</p>
  <p>I have a (maybe) simple problem I can't solve by myself.</p>
  <p>First I have a simple JSON File:</p>
  <pre><code>{
  &quot;results&quot;: [
  {
  &quot;entryID&quot;:10,
  &quot;date&quot;:&quot;24.12.201&quot;, 
  &quot;category&quot;:&quot;Best&quot;,
  &quot;title&quot;:&quot;Example title&quot;,
  &quot;textBody&quot;:&quot;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod.&quot;, 
  &quot;link&quot;:&quot;http://www.example.com&quot; },
  {
  &quot;entryID&quot;:9,
  &quot;date&quot;:&quot;24.12.201&quot;, 
  &quot;category&quot;:&quot;Best&quot;,
  &quot;title&quot;:&quot;title for ever&quot;,
  &quot;textBody&quot;:&quot;Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero.&quot;, 
  &quot;link&quot;:&quot;http://www.example.com&quot; }
  ]
  }
  </code></pre>
  <p>I use following struct for encoding:</p>
  <pre><code>struct Response: Codable {
      var results: [JSONResult]
  }
  
  struct JSONResult: Codable {
      var entryID: Int
      var category: String
      var title: String
      var textBody: String
      var link: String
  }
  </code></pre>
  <p>Decoding works as expected.</p>
  <p>If I want to save the JSON to file with this func:</p>
  <pre><code> func convertAndSaveFavoritestoJSON(item: JSONResult) {
          
          guard let url = URL(string: documentDirectory.appendingPathComponent(&quot;Favoriten.json&quot;).absoluteString)
                  else {
                      print(&quot;Invalid URL&quot;)
                      return
                  }
          
          do {
              let jsonData = try JSONEncoder().encode(favorites)
              let jsonString = String(data: jsonData, encoding: .utf8)!
              print(jsonString)
              try jsonString.write(to: url,
                                   atomically: true,
                                   encoding: .utf8)
          } catch { print(error) }
        
      }
  </code></pre>
  <p>the file on disks looks like following (the results array is missing):</p>
  <pre><code>[
  {
  &quot;entryID&quot;:10,
  &quot;title&quot;:&quot;Favorit&quot;,&quot;textBody&quot;:&quot;Lorem ipsum dolor sit amet, consetetur sadipscing elitr.&quot;,
  &quot;category&quot;:&quot;Hardware&quot;,
  &quot;link&quot;:&quot;http:\/\/example.com&quot;
  }
  ]
  </code></pre>
  <p>What can I do to save my struct in the same array format like my source?</p>
  <p>Any hints are welcome :-)</p>
  <p>Thank you
  Michael</p>