See here a function where I can make a a JSON Data object from a dictionary.
// MARK: - Example code
private func makeItemsJSON(_ items: [[String: Any]]) -> Data {
let json = ["items": items]
return try! JSONSerialization.data(withJSONObject: json)
}