title: How to convert list of dictionaries into Pyspark DataFrame
body: <p>I want to convert my list of dictionaries into DataFrame. This is the list:</p>
  
  <pre><code>mylist = 
  [
    {"type_activity_id":1,"type_activity_name":"xxx"},
    {"type_activity_id":2,"type_activity_name":"yyy"},
    {"type_activity_id":3,"type_activity_name":"zzz"}
  ]
  </code></pre>
  
  <p>This is my code:</p>
  
  <pre><code>from pyspark.sql.types import StringType
  
  df = spark.createDataFrame(mylist, StringType())
  
  df.show(2,False)
  
  +-----------------------------------------+
  |                                    value|
  +-----------------------------------------+
  |{type_activity_id=1,type_activity_id=xxx}|
  |{type_activity_id=2,type_activity_id=yyy}|
  |{type_activity_id=3,type_activity_id=zzz}|
  +-----------------------------------------+
  </code></pre>
  
  <p>I assume that I should provide some mapping and types for each column, but I don't know how to do it.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I also tried this:</p>
  
  <pre><code>schema = ArrayType(
      StructType([StructField("type_activity_id", IntegerType()),
                  StructField("type_activity_name", StringType())
                  ]))
  df = spark.createDataFrame(mylist, StringType())
  df = df.withColumn("value", from_json(df.value, schema))
  </code></pre>
  
  <p>But then I get <code>null</code> values:</p>
  
  <pre><code>+-----+
  |value|
  +-----+
  | null|
  | null|
  +-----+
  </code></pre>