How to create JSON from a dictionary in Swift 4?
After trying out various ways the below way is what worked for me for getting the exact format required by the backend.
var messageDictionary = [
"sender":"[email protected]",
"recipients":["[email protected]"],
"data":[
"text" : data
]
] as [String : Any]
let jsonData = try! JSONSerialization.data(withJSONObject: messageDictionary)
let jsonString = NSString(data: jsonData, encoding: String.Encoding.utf8.rawValue)