Being new to Spark, I am working on something and facing difficulty. Any leads will help. I am trying to create a JSON from dataframe which I have but toJSON function is not helping me out. So my output data frame is something like below :-
+---------+------------------+-------------------------+
|booking_id| status |count(status)|
+---------+------------------+-------------------------+
| 132 | rent count. | 6|
| 132 | rent booked | 24|
| 132 | rent delayed | 6|
| 134 | rent booked | 34|
| 134 | rent delayed. | 21|
The output I am looking for is a dataframe which will contain booking id and status and its count as Json
+---------+-------------------------------------------+
|booking_id| status_json
+---------+-------------------------------------------+
| 132 | { "rent count": 6, "rent booked": 24, "rent delayed": 6}
| 134 | { "rent booked": 34, "rent delayed": 21}
Thanks in advance.
mapcolumn with staus and countstatus columns. ThengroupBy,agg(collect_list("yourmapcolumn")), finally calltoJSON