title: swift parse json - The data couldn’t be read because it isn’t in the correct format
body: <p>Here is struct codable code:</p>
  <pre><code>import Foundation
  
  public struct TaskID: Codable {
      let embedded: Embedded
  }
  
  public struct Embedded: Codable {
      let task: [Task]
  }
  
  public struct Task : Codable {
  
      let embedded: EmbeddedVariable
      let id : String
      let name: String
      let assignee: String
      let created: String
      let processDefinitionId: String
  }
  
  public struct EmbeddedVariable: Codable {
  
      let variable : [Variables]
  }
  
  public struct Variables: Codable {
  
      let value : String
      let name: String
  }
  </code></pre>
  <p>I have tried by codingKey and also tried using _embedded too. Face same issue.</p>
  <p><strong>Error log:</strong> Response could not be decoded because of error:</p>
  <pre><code> Alamofire.AFError.
   ResponseSerializationFailureReason.decodingFailed(error: Swift.DecodingError.typeMismatch(Swift.Dictionary&lt;Swift.String, Any&gt;, Swift.DecodingError.Context(codingPath: [], debugDescription: &quot;Expected to decode Dictionary&lt;String, Any&gt; but found an array instead.&quot;, underlyingError: nil)))))
  </code></pre>
  <p>The data couldn’t be read because it isn’t in the correct format.</p>
  <p>Here is the code for JSONSerialization:</p>
  <pre><code>      // MARK: - URLRequestConvertible
  func asURLRequest() throws -&gt; URLRequest {
      let url = try K.ProductionServer.baseURL.asURL()
      
      var urlRequest = URLRequest(url: url.appendingPathComponent(path))
      print(urlRequest)
      // HTTP Method
      urlRequest.httpMethod = method.rawValue
     
      let authToken = UserDefaults.standard.string(forKey: &quot;authToken&quot;)
      let bearerToken: String = &quot;Bearer &quot; + (authToken ?? &quot;&quot;)
      print(&quot;baearer token::\(bearerToken)&quot;)
      
      // Common Headers
      urlRequest.setValue(ContentType.json.rawValue, forHTTPHeaderField: HTTPHeaderField.acceptType.rawValue)
      urlRequest.setValue(ContentType.json.rawValue, forHTTPHeaderField: HTTPHeaderField.contentType.rawValue)
      urlRequest.setValue(bearerToken, forHTTPHeaderField: HTTPHeaderField.authentication.rawValue)
      
      // Parameters
      if let parameters = parameters {
          do {
              urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: [])
          } catch {
              throw AFError.parameterEncodingFailed(reason: .jsonEncodingFailed(error: error))
          }
      }
      
      return urlRequest
  }
  </code></pre>
  <p>Here is the code json return response:</p>
  <pre><code>   import Foundation
    import Alamofire
  
  public class APIClient {
  @discardableResult
  private static func performRequest&lt;T:Decodable&gt;(route:APIRouter, decoder: JSONDecoder = JSONDecoder(), completion:@escaping (AFResult&lt;T&gt;)-&gt;Void) -&gt; DataRequest {
              
      return AF.request(route)
                      .responseDecodable (decoder: decoder){ (response: AFDataResponse&lt;T&gt;) in
                          completion(response.result)
                          print(&quot;framework response::&quot;,response.result)
      }
  }
  
  public static func taskID(id: String, completion:@escaping (AFResult&lt;MyTaskData&gt;)-&gt;Void) {
      
      performRequest(route: APIRouter.TaskById(id: id), completion: completion)
  }
  
  
  }//APIClient
  </code></pre>