title: Codable protocol error "The given data was not valid JSON."
body: <p>I am getting an error having to do with the codable protocol </p>
  
  <pre><code>struct UsersResponse : Codable {
      let directoryItems: [DirectoryItem]
      enum CodingKeys : String, CodingKey {
          case directoryItems = "directory_items"
      }
  }
  
  struct DirectoryItem : Codable {
      let user : User
  }
  
  struct User : Codable {
      let id: Int
      let userName: String
      let imageURL: String
      enum CodingKeys : String, CodingKey {
          case id = "id"
          case userName = "username"
          case imageURL = "avatar_template"
      }
  }
  
  </code></pre>
  
  <p>This is my JSON response on Postman, the keys are well defined in the protocol, honestly I don't really know what is going wrong. 
  Here is the full error object. 
  dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.})))</p>
  
  <pre><code>{
  "directory_items": [
  {
  "id": 0,
  "likes_received": 0,
  "likes_given": 0,
  "topics_entered": 0,
  "topic_count": 0,
  "post_count": 0,
  "posts_read": 0,
  "days_visited": 0,
  "user": {
  "id": 0,
  "username": "string",
  "avatar_template": "string",
  "name": "string",
  "title": { }
  }
  }
  ],
  "total_rows_directory_items": 0,
  "load_more_directory_items": "string"
  }
  </code></pre>
  
  <p>This is where I ask for the data </p>
  
  <pre><code>func send&lt;T: APIRequest&gt;(request: T, completion: @escaping(Result&lt;T.Response, Error&gt;) -&gt; ()) {
          let request = request.requestWithBaseUrl()
          let task = session.dataTask(with: request) { data, response, error in
              do {
                  guard let response = response as? HTTPURLResponse else { return }
                  if response.statusCode &gt;= 400 &amp;&amp; response.statusCode &lt; 500 {
                      if let data = data {
                          let errorModel = try JSONDecoder().decode(DiscourseAPIError.self, from: data)
                          DispatchQueue.main.async {
                              let errorString = errorModel.errors?.joined(separator: ", ") ?? "Unknown error"
                              completion(.failure(NSError(domain: "request error", code: 0, userInfo: [NSLocalizedDescriptionKey: errorString])))
                          }
                      } else {
                          DispatchQueue.main.async {
                              completion(.failure(SessionAPIError.emptyData))
                          }
                      }
                  }
                  if let data = data {
                      let json = try JSONSerialization.jsonObject(with: data) as! Dictionary&lt;String, AnyObject&gt;
                      print(json)
                      let model = try JSONDecoder().decode(T.Response.self, from: data)
                      DispatchQueue.main.async {
                          completion(.success(model))
                      }
                  } else {
                      DispatchQueue.main.async {
                          completion(.failure(SessionAPIError.emptyData))
                      }
                  }
              } catch {
                  DispatchQueue.main.async {
                      print(error)
                      completion(.failure(error))
                  }
              }
          }
          task.resume()
      }
  }
  </code></pre>