how to convert json string to dataframe on spark

前端 未结 7 1365
臣服心动
臣服心动 2020-11-27 15:39

I want to convert string variable below to dataframe on spark.

val jsonStr = \"{ \"metadata\": { \"key\": 84896, \"value\": 54 }}\"

I know

7条回答
  •  感动是毒
    2020-11-27 16:06

    simple_json = '{"results":[{"a":1,"b":2,"c":"name"},{"a":2,"b":5,"c":"foo"}]}'
    rddjson = sc.parallelize([simple_json])
    df = sqlContext.read.json(rddjson)
    

    The reference to the answer is https://stackoverflow.com/a/49399359/2187751

提交回复
热议问题