title: dataframe Spark scala explode json array
body: <p>Let's say I have a dataframe which looks like this:</p>
  
  <pre><code>+--------------------+--------------------+--------------------------------------------------------------+
  |                id  |           Name     |                                                       Payment|
  +--------------------+--------------------+--------------------------------------------------------------+
  |                1   |           James    |[ {"@id": 1, "currency":"GBP"},{"@id": 2, "currency": "USD"} ]|
  +--------------------+--------------------+--------------------------------------------------------------+
  </code></pre>
  
  <p>And the schema is:</p>
  
  <p>root</p>
  
  <pre><code>|-- id: integer (nullable = true)
  |-- Name: string (nullable = true)   
  |-- Payment: string (nullable = true)
  </code></pre>
  
  <p>How can I explode the above JSON array into below:</p>
  
  <pre><code>+--------------------+--------------------+-------------------------------+
  |                id  |           Name     |                        Payment|
  +--------------------+--------------------+-------------------------------+
  |                1   |           James    |   {"@id":1, "currency":"GBP"} |
  +--------------------+--------------------+-------------------------------+
  |                1   |           James    |   {"@id":2, "currency":"USD"} |
  +--------------------+--------------------+-------------------------------+
  </code></pre>
  
  <p>I've been trying to use the explode functionality like the below, but it's not working. It's giving an error about not being able to explode string types, and that it expects either a map or array. This makes sense given the schema denotes it's a string, rather than an array/map, but I'm not sure how to convert this into an appropriate format.</p>
  
  <pre><code>val newDF = dataframe.withColumn("nestedPayment", explode(dataframe.col("Payment")))
  </code></pre>
  
  <p>Any help is greatly appreciated!</p>