I have a method, which will return a [String: Any]
dictionary as below,
func getDetailDictionary() -> [String: Any] {
// demo code
let followers = [1, 2, 3, 4, 5]
return [
"name": "sample name",
"followers": followers
]
}
I need to convert this object to JSON
, so that I can send it back to the client as a ResponseRepresentable
object.
I used the following to prepare the JSON object:
let jsonData = try JSON(node: getDetailDictionary())
But this giving error, telling this doesn't match any available overloads. I don't think [String:Any]
type is not handled in JSON(node: )
method implementation. Is there any way we can get this issue resolved in Vapor?