Is there any method where i can create a json from a spark dataframe by not using those fields which are null:
Lets suppose i have a data frame:
+-------+----------------+
| name| hit_songs|
+-------+----------------+
|beatles|[help, hey jude]|
| romeo| [eres mia]|
| juliet| null |
+-------+----------------+
i want to convert it into a json like:
[{
name: "beatles",
hit_songs: [help, hey jude]
},
{
name: "romeo",
hit_songs: [eres mia]
},
{
name: "juliet"
}
]
i dont want the field hit_songs in the json_object if its value is null