title: How to cast JSONSerialization result to an [[String:Any]] data structure?
body: <p>For my question I have prepared <a href="https://github.com/afarber/ios-questions/tree/master/JsonPlayground.playground" rel="nofollow noreferrer">a simple Playground at Github</a>:</p>
  <p><a href="https://i.stack.imgur.com/37Gyp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/37Gyp.jpg" alt="Xcode screenshot" /></a></p>
  <p>Parsing a String to JSON works ok with the code:</p>
  <pre><code>import UIKit
  
  var str =
  &quot;&quot;&quot;
  {&quot;data&quot;: [{&quot;uid&quot;:9844,&quot;elo&quot;:2900,&quot;motto&quot;:null,&quot;given&quot;:&quot;Ольга&quot;,&quot;avg_time&quot;:&quot;04:13&quot;,&quot;avg_score&quot;:20.5},{&quot;uid&quot;:13480,&quot;elo&quot;:2875,&quot;motto&quot;:null,&quot;given&quot;:&quot;Наталья&quot;,&quot;avg_time&quot;:&quot;03:27&quot;,&quot;avg_score&quot;:21.0},{&quot;uid&quot;:14376,&quot;elo&quot;:2825,&quot;motto&quot;:null,&quot;given&quot;:&quot;Дмитрий&quot;,&quot;avg_time&quot;:&quot;04:51&quot;,&quot;avg_score&quot;:19.8},{&quot;uid&quot;:8458,&quot;elo&quot;:2734,&quot;motto&quot;:null,&quot;given&quot;:&quot;Аля&quot;,&quot;avg_time&quot;:&quot;03:03&quot;,&quot;avg_score&quot;:21.1},{&quot;uid&quot;:18384,&quot;elo&quot;:2723,&quot;motto&quot;:null,&quot;given&quot;:&quot;Светлана&quot;,&quot;avg_time&quot;:&quot;02:25&quot;,&quot;avg_score&quot;:19.6},{&quot;uid&quot;:18125,&quot;elo&quot;:2720,&quot;motto&quot;:null,&quot;given&quot;:&quot;Людмила&quot;,&quot;avg_time&quot;:&quot;03:57&quot;,&quot;avg_score&quot;:20.2},{&quot;uid&quot;:14382,&quot;elo&quot;:2708,&quot;motto&quot;:null,&quot;given&quot;:&quot;Виктория&quot;,&quot;avg_time&quot;:&quot;03:33&quot;,&quot;avg_score&quot;:19.1},{&quot;uid&quot;:8380,&quot;elo&quot;:2687,&quot;motto&quot;:null,&quot;given&quot;:&quot;Ihor&quot;,&quot;avg_time&quot;:&quot;01:44&quot;,&quot;avg_score&quot;:18.8},{&quot;uid&quot;:15917,&quot;elo&quot;:2681,&quot;motto&quot;:null,&quot;given&quot;:&quot;Наталья&quot;,&quot;avg_time&quot;:&quot;04:53&quot;,&quot;avg_score&quot;:20.1},{&quot;uid&quot;:19650,&quot;elo&quot;:2673,&quot;motto&quot;:&quot;Ты не проиграл, пока не сдался.&quot;,&quot;given&quot;:&quot;Елена&quot;,&quot;avg_time&quot;:&quot;01:46&quot;,&quot;avg_score&quot;:18.0},{&quot;uid&quot;:13797,&quot;elo&quot;:2653,&quot;motto&quot;:null,&quot;given&quot;:&quot;Irina&quot;,&quot;avg_time&quot;:&quot;03:27&quot;,&quot;avg_score&quot;:19.5},{&quot;uid&quot;:13014,&quot;elo&quot;:2648,&quot;motto&quot;:null,&quot;given&quot;:&quot;Светлана&quot;,&quot;avg_time&quot;:&quot;05:32&quot;,&quot;avg_score&quot;:21.6},{&quot;uid&quot;:18811,&quot;elo&quot;:2634,&quot;motto&quot;:null,&quot;given&quot;:&quot;Алеся&quot;,&quot;avg_time&quot;:&quot;03:45&quot;,&quot;avg_score&quot;:19.1},{&quot;uid&quot;:13455,&quot;elo&quot;:2630,&quot;motto&quot;:null,&quot;given&quot;:&quot;Татьяна&quot;,&quot;avg_time&quot;:&quot;02:43&quot;,&quot;avg_score&quot;:18.1},{&quot;uid&quot;:16783,&quot;elo&quot;:2614,&quot;motto&quot;:null,&quot;given&quot;:&quot;Татьяна&quot;,&quot;avg_time&quot;:&quot;02:28&quot;,&quot;avg_score&quot;:18.3}]}
  &quot;&quot;&quot;
  
  guard let data = str.data(using: .utf8),
        let json = try? JSONSerialization.jsonObject(with: data, options: [])
      else { fatalError(&quot;Error&quot;) }
  print(json)
  </code></pre>
  <p>but how can I take the list of the objects referenced by the &quot;data&quot; attribute and cast it to a <code>[[String:Any]]</code> data structure?</p>
  <p>I need it for the later <a href="https://developer.apple.com/documentation/coredata/nsbatchinsertrequest" rel="nofollow noreferrer">NSBatchInsertRequest</a> call.</p>
  <p>I have tried <code>print(json[&quot;data&quot;] as? [[String:Any]])</code> and also <code>let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String:[[String:Any]]]</code> but get syntax errors:</p>
  <p><a href="https://i.stack.imgur.com/yGtcx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yGtcx.jpg" alt="screenshot" /></a></p>