I have Array[Row] called arr (I obtained it after df.collect()) that I want to pass in my JSON string as key and value pairs:
val result = """{"field1": "A", "arr": [""" + arr + """]}"""
It should be:
{"field1": "A", "arr": [
{"name":"Ford", "model": "Fiesta"},
{"name":"Ford", "model": "Mustang"},
...
]}
If I do it the way that I showed above, it will not work.
Should I iterate over this array and manually define each parameter?:
arr.get(i).get(arr.get(i).fieldIndex("field1")).toString()
to_json(with Dataframes) ortoJSONwith RDDs? What does the result ofdf.collect()look like ?df.toJSON, then it returnsDataset[String]. What do I do with it?