title: Infer schema from json string
body: <p>I have this dataframe :</p>
  <pre><code>cSchema = StructType([StructField(&quot;id1&quot;, StringType()), StructField(&quot;id2&quot;, StringType()), StructField(&quot;params&quot;, StringType())\
                        ,StructField(&quot;Col2&quot;, IntegerType())])
  
  test_list = [[1, 2, '{&quot;param1&quot;: &quot;val1&quot;, &quot;param2&quot;: &quot;val2&quot;}', 1], [1, 3, '{&quot;param1&quot;: &quot;val4&quot;, &quot;param2&quot;: &quot;val5&quot;}', 3]]
  
  df = spark.createDataFrame(test_list,schema=cSchema) 
  
  +---+---+--------------------+----+
  |id1|id2|              params|Col2|
  +---+---+--------------------+----+
  |  1|  2|{&quot;param1&quot;: &quot;val1&quot;...|   1|
  |  1|  3|{&quot;param1&quot;: &quot;val4&quot;...|   3|
  +---+---+--------------------+----+
  </code></pre>
  <p>I want to explode params into columns :</p>
  <pre><code>+---+---+----+------+------+
  |id1|id2|Col2|param1|param2|
  +---+---+----+------+------+
  |  1|  2|   1|  val1|  val2|
  |  1|  3|   3|  val4|  val5|
  +---+---+----+------+------+
  </code></pre>
  <p>So I coded this :</p>
  <pre><code>schema2 = StructType([StructField(&quot;param1&quot;, StringType()), StructField(&quot;param2&quot;, StringType())])
  
  df.withColumn(
    &quot;params&quot;, from_json(&quot;params&quot;, schema2)
  ).select(
    col('id1'), col('id2'),col('Col2'), col('params.*')
  ).show()
  </code></pre>
  <p>The problem is that <code>params</code> schema is dynamic (variable <code>schema2</code>), he may change from one execution to another, so I need to infer the schema dynamically (It's ok to have all columns with String Type)... And I can't figure out of a way to do this..</p>
  <p>Can anyone help me up with that please ?</p>