title: How can I convert a Realm object to JSON in Swift?
body: <p>I have two Realm tables declared:</p>
  
  <pre><code>class Task: Object {
      dynamic var taskID: String = ""
      let taskAssignedTo = List&lt;Contacts&gt;()
  }
  
  class Contacts: Object {
      dynamic var contactEmail: String = ""
      dynamic var contactName: String = ""
  }
  </code></pre>
  
  <p>Final goal is to convert the Task Realm object into JSON. The method I'm thinking of is:</p>
  
  <p>Convert the object to a dictionary using a method within the class</p>
  
  <pre><code>func taskToDictionary() -&gt; [String: AnyObject] {
      return [
          "taskID" : self.taskID,
          "taskAssignedTo" : self.taskAssignedTo._rlmArray.count //Not sure how to get the array
      ]
  }
  </code></pre>
  
  <p>Convert the resulting dictionary into JSON with SwiftyJSON</p>
  
  <pre><code>let taskObject = Task()
  let newTaskJSON = JSON(taskObject.taskToDictionary())
  </code></pre>
  
  <p>Right now, this converts ok, but:</p>
  
  <ol>
  <li>Is there a better way to do this? </li>
  <li>How can I convert the RLMArray into an array for JSON conversion?</li>
  </ol>