title: How to convert struct to json Swift
body: <p>I need to create JSON like this, but my code doesn't work:</p>
  
  <pre><code>{
      "room": "string",
      "products": [{
          "name": "string",
          "quantity": 0
      }],
      "observations": "string",
      "date": "dd-mm-yyyy hh:mm:ss"
  }</code></pre>
  
  <p>I need convert this struct to JSON, and my code is: </p>
  
  <pre><code>
  struct Products: JSONSerializable {
      let name: String
      let quantity: Int   
  }
  struct Pedido: JSONSerializable{
      let room: String
      let products: Array
      let observations: String
      let date: NSDate
  }
  </code></pre>
  
  <p>this code doesn't work, return nil in log:</p>
  
  <pre><code>
   let JSONPedido = Pedido(room: receivedString,
                           products: products,
                           observations: observationString!,
                           date: date).ToJSON()
  </code></pre>