title: CoreData object to JSON in Swift 3
body: <p>I'm struggling to get my CoreData objects into JSON so that I can use it to send to a web server. </p>
  
  <p>This is how I currently fetch my objects from CoreData:</p>
  
  <pre><code>func fetchRecord() -&gt; [Record] {
  
      do {
          records = try context.fetch(Record.fetchRequest())
  
      } catch {
          print("Error fetching data from CoreData")
      }
      return records
  }
  </code></pre>
  
  <p>I am able to display this on to my tableView this way:</p>
  
  <pre><code>func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
      let cell = tableView.dequeueReusableCell(withIdentifier: "recordCell", for: indexPath) as! RecordCell
  
      cell.nameLbl.text = records[indexPath.row].name
      cell.quantityLbl.text = "Quantity: \(String(records[indexPath.row].quantity))"
      cell.dateLbl.text = dateString(date: records[indexPath.row].date)
  
      return cell
  }
  </code></pre>
  
  <p>I have attempted to loop inside my request like this:</p>
  
  <pre><code>for rec in records {
      print(rec)
  }
  </code></pre>
  
  <p>that gives out this:</p>
  
  <p><a href="https://i.stack.imgur.com/nUjEj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/nUjEj.png" alt="enter image description here"></a></p>
  
  <p>I have read a lot about ways to achieve this but none of them seem to really be of beneficial to me. Most of the examples out there shows how to get JSON to CoreData and not the other way. Does anyone know any good tutorials or documentation that can help me achieve this?</p>