title: How to convert Rows to JSON inside foreachPartition?
body: <p>Is there a way to convert Row to JSON inside foreachPartition?
  I have looked at <a href="https://stackoverflow.com/questions/41601874/how-to-convert-row-to-json-in-spark-2-scala">How to convert Row to json in Spark 2 Scala</a> .
  However this approach won't work as I can't access sqlContext from within foreachPartition and also my data contains nested type.</p>
  
  <pre><code> dataframe.foreachPartition { partitionOfRecords =&gt;
  
      ..
      val connectionString: ConnectionStringBuilder = new ConnectionStringBuilder(
                  eventHubsNamespace,
                  eventHubName,
                  policyName,
                  policyKey)
  
      val eventHubsClient: EventHubClient = EventHubClient.createFromConnectionString(connectionString.toString()).get()
  
      val json = /* CONVERT partitionOfRecords to JSON */
  
      val bytes = json.getBytes()
      val eventData = new EventData(bytes)
      eventHubsClient.send(eventData)
    }
  </code></pre>