How to use Spark SQL to parse the JSON array of objects

后端 未结 2 1170
慢半拍i
慢半拍i 2021-02-10 02:15

now has JSON data as follows

{\"Id\":11,\"data\":[{\"package\":\"com.browser1\",\"activetime\":60000},{\"package\":\"com.browser6\",\"activetime\":1205000},{\"pa         


        
2条回答
  •  时光说笑
    2021-02-10 02:23

    with @Shankar Koirala 's help , I learned how to use ' explode' to handle joson array.

      val df = sqlContext.sql("SELECT data FROM behavior")
    appActiveTime.select(explode(df("data"))).toDF("data")
      .select("data.package","data.activetime")
      .show(false)
    

提交回复
热议问题