how to convert json string to dataframe on spark

前端 未结 7 867
臣服心动
臣服心动 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:12

    you can now directly read json from Dataset[String]: https://spark.apache.org/docs/latest/sql-data-sources-json.html

    val otherPeopleDataset = spark.createDataset(
      """{"name":"Yin","address":{"city":"Columbus","state":"Ohio"}}""" :: Nil)
    val otherPeople = spark.read.json(otherPeopleDataset)
    otherPeople.show()
    // +---------------+----+
    // |        address|name|
    // +---------------+----+
    // |[Columbus,Ohio]| Yin|
    // +---------------+----+
    
    0 讨论(0)
提交回复
热议问题