Given a data frame,
+-----------------------------+
| id| name| payable| strategy|
+-----------------------------+
| 0| Joe| 100| st-1|
| 1| Tom| 200| st-2|
| 2| John| 300| st-1|
+-----------------------------+
What would be the most efficient way to convert each row to a JSON string such as follows,
{
"payload": {
"name": "Joe",
"payments": [
{
"strategy": "st-1",
"payable": 100
}
]
}
}
Currently I have UDF to manually stringify the provided columns, but I'm wondering whether there is a better way to achieve this. The to_json method is the best alternative I found so far but that takes only one column as an input.