Spark Row to JSON

后端 未结 4 2054
灰色年华
灰色年华 2020-11-30 03:19

I would like to create a JSON from a Spark v.1.6 (using scala) dataframe. I know that there is the simple solution of doing df.toJSON.

However, my probl

4条回答
  •  悲&欢浪女
    2020-11-30 04:15

    Spark 2.1 should have native support for this use case (see #15354).

    import org.apache.spark.sql.functions.to_json
    df.select(to_json(struct($"c1", $"c2", $"c3")))
    

提交回复
热议问题