title: How to parse string to array in Spark?
body: <p>How to flatten Array of Strings into multiple rows of a dataframe in Spark 2.2.0?</p>
  
  <p>Input Row <code>["foo", "bar"]</code></p>
  
  <pre><code>val inputDS = Seq("""["foo", "bar"]""").toDF
  </code></pre>
  
  <p>inputDS.printSchema()</p>
  
  <pre><code>root
   |-- value: string (nullable = true)
  </code></pre>
  
  <p>Input Dataset <code>inputDS</code></p>
  
  <pre><code>inputDS.show(false)
  
  value
  -----
  ["foo", "bar"]
  </code></pre>
  
  <p>Expected output dataset <code>outputDS</code></p>
  
  <pre><code>value
  -------
  "foo" |
  "bar" |
  </code></pre>
  
  <p>I tried <code>explode</code> function like below but it didn't quite work</p>
  
  <pre><code>inputDS.select(explode(from_json(col("value"), ArrayType(StringType))))
  </code></pre>
  
  <p>and I get the following error</p>
  
  <pre><code>org.apache.spark.sql.AnalysisException: cannot resolve 'jsontostructs(`value`)' due to data type mismatch: Input schema string must be a struct or an array of structs
  </code></pre>
  
  <p>Also tried the following</p>
  
  <pre><code>inputDS.select(explode(col("value")))
  </code></pre>
  
  <p>And I get the following error</p>
  
  <pre><code>org.apache.spark.sql.AnalysisException: cannot resolve 'explode(`value`)' due to data type mismatch: input to function explode should be array or map type, not StringType
  </code></pre>